Textview.textview
A widget to display the contents of a text buffer. If no buffer
is provided, a new one is created.
inherit Stk.Widget.widget
method as_textview : textview
method theme : Stk.Texttag.Theme.t
method wrap_mode : wrap_mode
method set_wrap_mode : wrap_mode -> unit
method buffer : B.t
method set_buffer : B.t -> unit
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 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.
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.
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 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.
method selection_range : Stk.Rope.range option
Returns the selected range, if any.
v#select_range ~start ~size
moves insert and selection cursors to select the specified range.
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.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.
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.
v#paste ()
calls textview
.replace_selection with the clipboard text, if any. Optional argument honor_readonly
is passed to textview
.replace_selection.
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.