core/text/edit

text_edit

Types

5

Command

Command :: enum u32 { None = 0, Undo = 1, Redo = 2, New_Line = 3, // multi-lines Cut = 4, Copy = 5, Paste = 6, Select_All = 7, Backspace = 8, Delete = 9, Delete_Word_Left = 10, Delete_Word_Right = 11, Left = 12, Right = 13, Up = 14, // multi-lines Down = 15, // multi-lines Word_Left = 16, Word_Right = 17, Start = 18, End = 19, Line_Start = 20, Line_End = 21, Select_Left = 22, Select_Right = 23, Select_Up = 24, // multi-lines Select_Down = 25, // multi-lines Select_Word_Left = 26, Select_Word_Right = 27, Select_Start = 28, Select_End = 29, Select_Line_Start = 30, Select_Line_End = 31, }Source

State

State :: struct { selection: [2]int, line_start: int, line_end: int, // initialized each "frame" with `begin` builder: ^strings.Builder, up_index: int, down_index: int, translate_by_grapheme: bool, // 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), user_data: rawptr, text: string, ok: bool, get_clipboard: proc(user_data: rawptr) -> (text: string, ok: bool), user_data: rawptr, text: string, ok: bool, clipboard_user_data: rawptr, }Source

Translation

Translation :: enum u32 { Start = 0, End = 1, Left = 2, Right = 3, Up = 4, Down = 5, Word_Left = 6, Word_Right = 7, Word_Start = 8, Word_End = 9, Soft_Line_Start = 10, Soft_Line_End = 11, }Source

Constants

2

Procedures

29

clear_all

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

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

copy

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

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

init

init :: proc(s: ^State, undo_text_allocator: runtime.Allocator, undo_state_allocator: runtime.Allocator, undo_timeout = DEFAULT_UNDO_TIMEOUT)Source

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

paste

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

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

sorted_selection

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

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

Reference search

Find anything

Documentation preferences

Settings

System theme variants

Used only while Theme is set to System.