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.
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.
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.
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.
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.
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.
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.
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.
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.
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.