package mosaic
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=9e4e90d17f9b2af1b07071fe425bc2c519c849c4f1d1ab73cde512be2d874849
sha512=06e9c4a741590942e81a27738d0b5c0413fafec8cf3b7dae047ad69f155e7b718aa4223818dc161b7d028efffcfd3365905e264d6fd31d453910ddfa91dcf9b9
doc/mosaic.ui/Mosaic_ui/Edit_buffer/index.html
Module Mosaic_ui.Edit_bufferSource
Grapheme-aware text editing buffer with cursor, selection, and undo.
Grapheme-aware text editing buffer.
A mutable buffer that tracks cursor position, selection, and undo history in terms of Unicode grapheme clusters. Content may contain newlines for multi-line editing.
The type for mutable editing buffers.
Helpers
strip_newlines s is s with all CR, LF, and CRLF sequences removed.
Note. When s contains no newline characters the original string is returned without allocation.
Constructors
val create :
?max_length:int ->
?width_method:Glyph.width_method ->
?tab_width:int ->
string ->
tcreate ?max_length ?width_method ?tab_width initial is a buffer whose initial content is initial, with cursor at the end.
max_length is the maximum number of grapheme clusters the buffer may hold. initial is truncated to max_length grapheme clusters if it exceeds that limit. max_length defaults to 1000 and is clamped to >= 0.
width_method controls how grapheme display widths are computed. Defaults to `Unicode.
tab_width is the display width of tab characters. Defaults to 2 and is clamped to >= 1.
See also set_max_length.
Content
set_text t s replaces the content of t with s.
s is truncated to max_length t grapheme clusters if it exceeds that limit. The cursor moves to the end and any active selection is cleared. No undo point is saved.
display_width t is the total display width of t in terminal columns.
Line information
cursor_col t is the grapheme column of the cursor within its logical line.
Cursor
cursor t is the cursor position as a 0-based grapheme cluster offset. The value is in [0;length t].
set_cursor t pos moves the cursor to pos, clamped to [0;length t]. Clears any active selection.
set_cursor_offset ?select t pos moves the cursor to pos, clamped to [0;length t].
When select is true, extends or creates a selection anchored at the previous cursor position. When select is false (default), any active selection is cleared.
See also set_cursor.
cursor_display_offset t is the display column of the cursor in terminal columns.
Selection
selection t is Some (lo, hi) when a selection is active, where lo < hi are grapheme cluster offsets. None when no selection is active.
selected_text t is the text of the current selection, or "" if no selection is active.
clear_selection t clears the active selection without moving the cursor.
Editing
insert t s is true iff inserting s changed the text of t.
If a selection is active it is deleted first. Then s is inserted at the cursor position. The result is truncated to max_length t grapheme clusters. An undo point is saved before any modification.
delete_backward t is true iff a deletion changed the text of t.
If a selection is active the selected text is deleted. Otherwise the grapheme cluster immediately before the cursor (Backspace behaviour) is deleted. An undo point is saved before any modification.
delete_forward t is true iff a deletion changed the text of t.
If a selection is active the selected text is deleted. Otherwise the grapheme cluster immediately after the cursor (Delete behaviour) is deleted. An undo point is saved before any modification.
delete_word_backward t is true iff a deletion changed the text of t.
Deletes from the cursor to the previous word boundary. An undo point is saved before any modification.
delete_word_forward t is true iff a deletion changed the text of t.
Deletes from the cursor to the next word boundary. An undo point is saved before any modification.
delete_to_line_start t is true iff a deletion changed the text of t.
Deletes from the cursor to the start of the current logical line. An undo point is saved before any modification.
delete_to_line_end t is true iff a deletion changed the text of t.
Deletes from the cursor to the end of the current logical line (before any newline). Returns false when the cursor is already at the line end. An undo point is saved before any modification.
delete_to_start t is true iff a deletion changed the text of t.
Deletes from the cursor to the start of the buffer. An undo point is saved before any modification.
delete_to_end t is true iff a deletion changed the text of t.
Deletes from the cursor to the end of the buffer. An undo point is saved before any modification.
delete_line t is true iff a deletion changed the text of t.
Deletes the current logical line including its trailing line separator. An undo point is saved before any modification.
Cursor movement
Movement operations return true iff the cursor position changed.
When select is true the operation extends or creates a selection. When select is false (default) any active selection is cleared. If a selection was active and select is false, the cursor moves to the selection edge in the direction of movement.
move_left ?select t is true iff the cursor moved.
Moves the cursor one grapheme cluster to the left. select defaults to false.
move_right ?select t is true iff the cursor moved.
Moves the cursor one grapheme cluster to the right. select defaults to false.
move_word_forward ?select t is true iff the cursor moved.
Moves the cursor to the next word boundary. select defaults to false.
move_word_backward ?select t is true iff the cursor moved.
Moves the cursor to the previous word boundary. select defaults to false.
move_home ?select t is true iff the cursor moved.
Moves the cursor to the start of the buffer. select defaults to false.
move_end ?select t is true iff the cursor moved.
Moves the cursor to the end of the buffer. select defaults to false.
move_line_start ?select t is true iff the cursor moved.
Moves the cursor to the start of the current logical line. select defaults to false.
move_line_end ?select t is true iff the cursor moved.
Moves the cursor to the end of the current logical line, before any trailing newline. select defaults to false.
Undo and redo
undo t is true iff undoing restored a previous state.
Restores the most recent undo point. Returns false when no undo history is available.
redo t is true iff redoing re-applied a change.
Re-applies the most recently undone change. Returns false when no redo history is available.
Limits
set_max_length t n sets the maximum grapheme cluster count of t to n, clamped to >= 0. If the current content exceeds n grapheme clusters it is truncated to fit.
See also create.
Offset conversions
line_of_offset t pos is the 0-based logical line containing grapheme offset pos. pos is clamped to [0;length t].
col_of_offset t pos is the grapheme column of pos within its logical line. pos is clamped to [0;length t].
line_start t line is the grapheme offset of the first character on line. line is clamped to [0;line_count t - 1].
line_end t line is the grapheme offset past the last character on line, before the newline (or at buffer end for the last line). line is clamped to [0;line_count t - 1].