UI module

handle_key

procedureextensionexperimentalsince 0.31.0Source

Apply one KEY or TEXT input event to edit. style is the text style the lines are drawn in (vertical movement measures with it); page_lines is how many lines a page is.

Example↗
edit: Text_Edit;
defer free_text_edit(*edit);
ui := headless();
defer free_ui(*ui);

event: Input_Event;
event.kind = .TEXT;
event.character = #char "h";
result := handle_key(*ui, *edit, event, .{}, .{}, 10);
assert(result.changed && contents(*edit) == "h");
handle_key :: (
    ui: *UI_State,
    edit: *Text_Edit,
    event: Input_Event,
    style: Text_Style,
    options: Editor_Options,
    page_lines: int
) -> Key_Result

Apply one KEY or TEXT input event to edit. style is the text style the lines are drawn in (vertical movement measures with it); page_lines is how many lines a page is.

Parameters

ui: *UI_State
the UI, used for measuring and the clipboard.
edit: *Text_Edit
the text being edited.
event: Input_Event
the KEY or TEXT event.
style: Text_Style
the text style the lines are drawn in, used to measure vertical moves.
options: Editor_Options
read-only mode and the tab width.
page_lines: int
how many lines Page Up and Page Down move.

Returns

Example↗
edit: Text_Edit;
defer free_text_edit(*edit);
ui := headless();
defer free_ui(*ui);

event: Input_Event;
event.kind = .TEXT;
event.character = #char "h";
result := handle_key(*ui, *edit, event, .{}, .{}, 10);
assert(result.changed && contents(*edit) == "h");

See also