Text edit primitives to use in a text box. Based off the articles by rxi: - [[ https://rxi.github.io/textbox_behaviour.html ]] - [[ https://rxi.github.io/a_simple_undo_system.html ]]

Collection Info

View Source
Collection
core
Path
text/edit
Entries
36

Source Files

Constants

2

DEFAULT_UNDO_TIMEOUT #

Source
DEFAULT_UNDO_TIMEOUT :: 300 * time.Millisecond

MULTILINE_COMMANDS #

Source
MULTILINE_COMMANDS :: Command_Set{.New_Line, .Up, .Down, .Select_Up, .Select_Down}

Types

5

Procedures

29

clear_all #

Source
clear_all :: proc(s: ^State) -> (cleared: bool) {…}

returns true when the builder had content to be cleared clear builder&selection and the undo|redo stacks

copy #

Source
copy :: proc(s: ^State) -> bool {…}

try and copy the currently selected text to the clipboard State.set_clipboard needs to be assigned

destroy #

Source
destroy :: proc(s: ^State) {…}

clear undo|redo strings and delete their stacks

has_selection #

Source
has_selection :: proc(s: ^State) -> bool {…}

true if selection head and tail dont match and form a selection of multiple characters

init #

Source
init :: proc(s: ^State, undo_text_allocator, undo_state_allocator: Allocator, undo_timeout: Duration = DEFAULT_UNDO_TIMEOUT) {…}

init the state to some timeout and set the respective allocators - undo_state_allocator dictates the dynamic undo|redo arrays allocators - undo_text_allocator is the allocator which allocates strings only

input_rune #

Source
input_rune :: proc(s: ^State, r: rune) {…}

insert a single rune into the edit state - deletes the current selection

input_runes #

Source
input_runes :: proc(s: ^State, text: []rune) {…}

insert slice of runes into the edit state - deletes the current selection

input_text #

Source
input_text :: proc(s: ^State, text: string) -> int {…}

insert text into the edit state - deletes the current selection

paste #

Source
paste :: proc(s: ^State) -> bool {…}

reinsert whatever the get_clipboard would return State.get_clipboard needs to be assigned

remove #

Source
remove :: proc(s: ^State, lo, hi: int) {…}

remove the wanted range withing, usually the selection within byte indices

selection_delete #

Source
selection_delete :: proc(s: ^State) {…}

delete the current selection range and set the proper selection afterwards

setup_once #

Source
setup_once :: proc(s: ^State, builder: ^Builder) {…}

setup the builder, selection and undo|redo state once allowing to retain selection

sorted_selection #

Source
sorted_selection :: proc(s: ^State) -> (lo, hi: int) {…}

return the clamped lo/hi of the current selection since the selection[0] moves around and could be ahead of selection[1] useful when rendering and needing left->right

undo_check #

Source
undo_check :: proc(s: ^State) {…}

clear redo stack and check if the undo timeout gets hit

undo_clear #

Source
undo_clear :: proc(s: ^State, undo: ^[dynamic]^Undo_State) {…}

iteratively clearn the undo|redo stack and free each allocated text state

update_time #

Source
update_time :: proc(s: ^State) {…}

update current time so "insert" can check for timeouts