package stk

  1. Overview
  2. Docs

A widget to display the contents of a text buffer. If no buffer is provided, a new one is created.

method as_textview : textview

Properties

method theme : Stk.Texttag.Theme.t
method set_theme : string -> unit
method editable : bool
method set_editable : bool -> unit
method cursor_width : int
method set_cursor_width : int -> unit
method show_cursors : bool
method set_show_cursors : bool -> unit
method show_line_numbers : bool
method set_show_line_numbers : bool -> unit
method show_line_markers : bool
method set_show_line_markers : bool -> unit
method highlight_current_line : bool
method set_highlight_current_line : bool -> unit
method wrap_mode : wrap_mode
method set_wrap_mode : wrap_mode -> unit

Buffer

method buffer : B.t
method set_buffer : B.t -> unit
method line_count : int

Returns the number of lines in the buffer.

method char_count : int

Returns the number of characters in the buffer.

method text : ?start:int -> ?size:int -> ?stop:int -> unit -> string

v#text () returns contents of the buffer as a string. Optional arguments:

  • start: the start of range to retrieve (default is 0).
  • size: the size of range to retrieve.
  • stop: if size is not provided, the end of the range to retrieve.
method set_source_language : string option -> unit
method source_language : string option

Cursors

method insert_cursor : B.cursor

Returns the insert cursor. The insert cursor is the cursor where text is inserted when user types in. It is also the default cursor for methods accepting a cursor as optional argument. A textview must always have a current insert cursor. Raises Not_found if there is not insert cursor.

method set_insert_cursor : B.cursor -> bool

Set the insert cursor.

method is_insert_cursor : B.cursor -> bool

v#is_insert_cursor c returns true is c is the current insert cursor.

method selection_cursor : B.cursor

The insert cursor and selection cursor are the bounds of the current selection. A textview must always have a selection cursor, created when the widget is created. Raises Not_found if there is no selection cursor.

method cursor_offset : B.cursor -> int

Returns the given cursor offset.

method cursor_line_offset : B.cursor -> B.line_offset

Returns the given cursor position as Textbuffer.line_offset.

method add_cursor : ?props:Stk.Props.t -> ?gravity:B.cursor_gravity -> ?line:int -> ?char:int -> ?offset:int -> unit -> B.cursor

add_cursor () creates a new cursor. props can be provided to specify properties for this cursor (like its color). See Textbuffer.create_cursor for other arguments.

method remove_cursor : B.cursor -> unit

Removes the given cursor. Beware when removing the insert cursor, it should be replaced by another one.

method sel_to_ins_cursor : int option

Move selection cursor at the same position than the insert cursor.

method scroll_to_cursor : ?c:B.cursor -> unit -> unit

Make sure the insert cursor (or the cursor given with argument c) is in the displayed area.

Moving cursors

The following methods moves by default the insert cursor, or the selection cursor if a shift key is pressed. The optional argument c can be used to move another cursor.

The methods return the new offset of the cursor, or None if the cursor is invalid.

method move_to_line_start : ?c:B.cursor -> unit -> int option

Moves cursor to beginning of the line where the cursor is.

method move_to_line_end : ?c:B.cursor -> unit -> int option

Moves cursor to the end (before the newline character) of the line where the cursor is.

method line_forward : ?c:B.cursor -> int -> int option

Moves cursor to next line.

method line_backward : ?c:B.cursor -> int -> int option

Moves cursor to previous line.

method private next_dline : ?strict:bool -> iline:int -> idline:int -> int -> (int * int) option
method private prev_dline : ?strict:bool -> iline:int -> idline:int -> int -> (int * int) option
method dline_forward : ?c:B.cursor -> int -> int option

Moves cursor to next "display line", i.e. next part of the line is the line is wrapped and the cursor is not in the last part of the line, or the next line.

method dline_backward : ?c:B.cursor -> int -> int option

Moves cursor to previous "display line", i.e. the previous part of the line if the line is wrapped and the cursor is not in the first part, or the previous line.

method char_forward : ?c:B.cursor -> int -> int option

v#char_forward n moves cursor n characters forward.

method char_backward : ?c:B.cursor -> int -> int option

v#char_backward n moves cursor n characters backward.

method forward_to_word_end : ?c:B.cursor -> unit -> int option

Moves cursor to next word end, according to waht is a word character in the buffer (see Textbuffer.word_chars).

method backward_to_word_start : ?c:B.cursor -> unit -> int option

Moves cursor to previous word start.

method move_cursor : ?line:int -> ?char:int -> ?offset:int -> ?c:B.cursor -> unit -> int option

v#move_cursor () moves cursor to position specified by optional arguments as explained in Textbuffer.move_cursor.

method page_backward : ?c:B.cursor -> unit -> int option

Moves cursor one page backward. Depends on the displayed size of the widget. Typically associated to page-up key.

method page_forward : ?c:B.cursor -> unit -> int option

Moves cursor one page forward. Depends on the displayed size of the widget. Typically associated to page-down key.

Selection

method selection_range : Stk.Rope.range option

Returns the selected range, if any.

method selection : string

Returns the selected text, or "" if no text is selected.

method selection_opt : string option

Returns the selected text, if any.

method select_range : start:int -> size:int -> unit

v#select_range ~start ~size moves insert and selection cursors to select the specified range.

Inserting and deleting

method insert_at : ?honor_readonly:bool -> ?tags:Stk.Texttag.TSet.id list -> int -> string -> unit

v#insert_at offset string inserts string at offset. Options arguments:

  • honor_readonly specifies whether insertion is conditioned by the Props.editable property of tags. Default is false. It is called with true to insert the text the user types in.
  • tags specifies tags to associate to inserted characters.
method insert : ?honor_readonly:bool -> ?tags:Stk.Texttag.T.t list -> ?c:B.cursor -> string -> unit

Same as textview.insert_at but inserts at the position of the insert cursor or the position of a cursor given with argument c.

method delete : ?honor_readonly:bool -> ?start:int -> ?size:int -> unit -> string

v#delete () delete contents of buffer. Optional arguments:

  • start: the start of range to delete (default is 0).
  • size: the size of range to delete. Default is buffer size - start.
  • honor_readonly specifies whether deletion is conditioned by the Props.editable property of tags. Default is false. It is called with true to delete text from a user action.
method delete_backward : ?honor_readonly:bool -> ?c:B.cursor -> int -> string

v#delete_backward n deletes n characters backward the insert cursor. Optional arguments:

  • c to indicate another cursor to delete backward from.
  • honor_readonly (default is false): same as in textview.delete.
method delete_forward : ?honor_readonly:bool -> ?c:B.cursor -> int -> string

Same as textview.delete_backward but deletes forward from cursor.

method replace_selection : ?honor_readonly:bool -> string -> unit

v#replace_selection str replaces the selected range, if any, by str, in a single history action. If no range is selected, just insert str at insert cursor. Optional argument honor_readonly is passed to textview.delete and textview.insert methods.

method cut : ?honor_readonly:bool -> unit -> string option

v#cut () cut the selected range, if any, and copies it to clipboard. Optional argument honor_readonly is passed to textview.delete. Returns the deleted string, if any.

method paste : ?honor_readonly:bool -> unit -> unit

v#paste () calls textview.replace_selection with the clipboard text, if any. Optional argument honor_readonly is passed to textview.replace_selection.

method copy : unit

v#copy copies the selected text, if any, to clipbloard.

History

method in_action : 'a. (unit -> 'a) -> 'a

v#in_action f calls f() between Textbuffer.begin_action and Textbuffer.end_action. The result of f() is returned. If f() raises an exception, the action is ended and the exception if reraised.

method reset_history : unit

Reset buffer history.

method undo : unit

Undo last action.

method redo : unit

Redo last undo.

OCaml

Innovation. Community. Security.