package core:text/edit

⌘K
Ctrl+K
or
/

    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 ¶

    Command_Set :: distinct bit_set[Command; u32]

    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

    Undo_State ¶

    Undo_State :: struct {
    	selection: [2]int,
    	len:       int,
    	text:      [0]u8,
    }

    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 ¶

    begin :: proc(s: ^State, id: u64, builder: ^strings.Builder) {…}
     

    Call at the beginning of each frame

    clear_all ¶

    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 ¶

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

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

    current_selected_text ¶

    current_selected_text :: proc(s: ^State) -> string {…}
     

    return the currently selected text

    cut ¶

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

    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

    destroy ¶

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

    clear undo|redo strings and delete their stacks

    end ¶

    end :: proc(s: ^State) {…}
     

    Call at the end of each frame

    has_selection ¶

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

    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 ¶

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

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

    input_runes ¶

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

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

    input_text ¶

    input_text :: proc(s: ^State, text: string) {…}
     

    insert text into the edit state - deletes the current selection

    insert ¶

    insert :: proc(s: ^State, at: int, text: string) {…}
     

    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 ¶

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

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

    perform_command ¶

    perform_command :: proc(s: ^State, cmd: Command) {…}

    remove ¶

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

    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_once :: proc(s: ^State, builder: ^strings.Builder) {…}
     

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

    sorted_selection ¶

    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

    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-03 (vendor "odin") Windows_amd64 @ 2024-03-01 21:10:24.312653800 +0000 UTC