Home

Awesome

TextEditor

A backend for text editors. It implements the common textbox editing options, but is both rendering and input agnostic.

Keyboard input must be translated into operations like editor.delete(.right, .word) to emulate what a typical text box implementation would do when CTRL DELETE is pressed.

For mouse input, the editor component needs to be made aware about the font that is used. For this, an abstract font interface is required.

API

const TextEditor = @import("src/TextEditor.zig");

fn init(TextEditor.Buffer, initial_text: []const u8) InsertError!TextEditor {
fn deinit(*TextEditor) void;
fn setText(*TextEditor, text: []const u8) InsertError!void;
fn getText(TextEditor) []const u8;
fn getSubString(editor: TextEditor, start: usize, length: ?usize) []const u8;
fn setCursor(*TextEditor, offset: usize) SetCursorError!void;
fn moveCursor(*TextEditor, direction: EditDirection, unit: EditUnit) void;
fn delete(*TextEditor, direction: EditDirection, unit: EditUnit) void;
fn insertText(*TextEditor, text: []const u8) InsertError!void;
fn graphemeCount(TextEditor) usize;

Common Key Mappings

Keyboard InputEditor Call
Lefteditor.moveCursor(.left, .letter)
Righteditor.moveCursor(.right, .letter)
Ctrl+Lefteditor.moveCursor(.left, .word)
Ctrl+Righteditor.moveCursor(.right, .word)
Homeeditor.moveCursor(.left, .line)
Endeditor.moveCursor(.right, .line)
Backspaceeditor.delete(.left, .letter)
Deleteeditor.delete(.right, .letter)
Ctrl+Backspaceeditor.delete(.left, .word)
Ctrl+Deleteeditor.delete(.right, .word)
text inputtry editor.insert("string")