package core:text/edit
Overview
Based off the articles by rxi: https://rxi.github.io/textbox_behaviour.html https://rxi.github.io/a_simple_undo_system.html
Index
Types (5)
Constants (2)
Variables (0)
This section is empty.
Procedures (29)
- begin
- clear_all
- copy
- current_selected_text
- cut
- delete_to
- destroy
- end
- has_selection
- init
- input_rune
- input_runes
- input_text
- insert
- is_continuation_byte
- move_to
- paste
- perform_command
- remove
- select_to
- selection_delete
- setup_once
- sorted_selection
- translate_position
- undo
- undo_check
- undo_clear
- undo_state_push
- update_time
Procedure Groups (0)
This section is empty.
Types
Command ¶
Command :: enum u32 { None, Undo, Redo, New_Line, // multi-lines Cut, Copy, Paste, Select_All, Backspace, Delete, Delete_Word_Left, Delete_Word_Right, Left, Right, Up, // multi-lines Down, // multi-lines Word_Left, Word_Right, Start, End, Line_Start, Line_End, Select_Left, Select_Right, Select_Up, // multi-lines Select_Down, // multi-lines Select_Word_Left, Select_Word_Right, Select_Start, Select_End, Select_Line_Start, Select_Line_End, }
Related Procedures With Parameters
Command_Set ¶
Related Constants
State ¶
State :: struct { selection: [2]int, line_start: int, line_end: int, // initialized each "frame" with `begin` builder: ^strings.Builder, // let the caller store the text buffer data up_index: int, down_index: int, // undo undo: [dynamic]^Undo_State, redo: [dynamic]^Undo_State, undo_text_allocator: runtime.Allocator, id: u64, // Timeout information current_time: time.Tick, last_edit_time: time.Tick, undo_timeout: time.Duration, // Set these if you want cut/copy/paste functionality set_clipboard: proc(user_data: rawptr, text: string) -> (ok: bool), get_clipboard: proc(user_data: rawptr) -> (text: string, ok: bool), clipboard_user_data: rawptr, }
Related Procedures With Parameters
Translation ¶
Translation :: enum u32 { Start, End, Left, Right, Up, Down, Word_Left, Word_Right, Word_Start, Word_End, Soft_Line_Start, Soft_Line_End, }
Related Procedures With Parameters
Constants
DEFAULT_UNDO_TIMEOUT ¶
DEFAULT_UNDO_TIMEOUT: time.Duration : 300 * time.Millisecond
MULTILINE_COMMANDS ¶
MULTILINE_COMMANDS :: Command_Set{.New_Line, .Up, .Down, .Select_Up, .Select_Down}
Variables
This section is empty.
Procedures
begin ¶
Call at the beginning of each frame
clear_all ¶
returns true when the builder had content to be cleared clear builder&selection and the undo|redo stacks
copy ¶
try and copy the currently selected text to the clipboard State.set_clipboard needs to be assigned
current_selected_text ¶
return the currently selected text
cut ¶
copy & delete the current selection when copy() succeeds
delete_to ¶
delete_to :: proc(s: ^State, t: Translation) {…}
Deletes everything between the caret and resultant position
has_selection ¶
true if selection head and tail dont match and form a selection of multiple characters
init ¶
init :: proc(s: ^State, undo_text_allocator, undo_state_allocator: runtime.Allocator, undo_timeout: time.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 ¶
insert a single rune into the edit state - deletes the current selection
input_runes ¶
insert slice of runes into the edit state - deletes the current selection
input_text ¶
insert text into the edit state - deletes the current selection
insert ¶
insert a single rune into the edit state - deletes the current selection
move_to ¶
move_to :: proc(s: ^State, t: Translation) {…}
Moves the position of the caret (both sides of the selection)
paste ¶
reinsert whatever the get_clipboard would return State.get_clipboard needs to be assigned
remove ¶
remove the wanted range withing, usually the selection within byte indices
select_to ¶
select_to :: proc(s: ^State, t: Translation) {…}
Moves only the head of the selection and leaves the tail uneffected
selection_delete ¶
selection_delete :: proc(s: ^State) {…}
delete the current selection range and set the proper selection afterwards
setup_once ¶
setup the builder, selection and undo|redo state once allowing to retain selection
sorted_selection ¶
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
translate_position ¶
translate_position :: proc(s: ^State, t: Translation) -> int {…}
translates the caret position
undo ¶
undo :: proc(s: ^State, undo, redo: ^[dynamic]^Undo_State) {…}
pop undo|redo state - push to redo|undo - set selection & text
undo_check ¶
undo_check :: proc(s: ^State) {…}
clear redo stack and check if the undo timeout gets hit
undo_clear ¶
undo_clear :: proc(s: ^State, undo: ^[dynamic]^Undo_State) {…}
iteratively clearn the undo|redo stack and free each allocated text state
undo_state_push ¶
undo_state_push :: proc(s: ^State, undo: ^[dynamic]^Undo_State) -> runtime.Allocator_Error {…}
push current text state to the wanted undo|redo stack
update_time ¶
update_time :: proc(s: ^State) {…}
update current time so "insert" can check for timeouts
Procedure Groups
This section is empty.
Source Files
Generation Information
Generated with odin version dev-2024-12 (vendor "odin") Windows_amd64 @ 2024-12-17 21:11:02.069521100 +0000 UTC