Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ikskuh/texteditor
A backbone for text editors. No rendering, no input, but everything else.
https://github.com/ikskuh/texteditor
text text-editor unicode zig zig-package
Last synced: 17 days ago
JSON representation
A backbone for text editors. No rendering, no input, but everything else.
- Host: GitHub
- URL: https://github.com/ikskuh/texteditor
- Owner: ikskuh
- License: mit
- Created: 2022-05-16T09:45:21.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-20T22:31:51.000Z (5 months ago)
- Last Synced: 2024-10-22T23:34:34.451Z (21 days ago)
- Topics: text, text-editor, unicode, zig, zig-package
- Language: Zig
- Homepage:
- Size: 28.3 KB
- Stars: 46
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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
```zig
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 Input | Editor Call |
| ---------------- | ------------------------------------ |
| `Left` | `editor.moveCursor(.left, .letter)` |
| `Right` | `editor.moveCursor(.right, .letter)` |
| `Ctrl+Left` | `editor.moveCursor(.left, .word)` |
| `Ctrl+Right` | `editor.moveCursor(.right, .word)` |
| `Home` | `editor.moveCursor(.left, .line)` |
| `End` | `editor.moveCursor(.right, .line)` |
| `Backspace` | `editor.delete(.left, .letter)` |
| `Delete` | `editor.delete(.right, .letter)` |
| `Ctrl+Backspace` | `editor.delete(.left, .word)` |
| `Ctrl+Delete` | `editor.delete(.right, .word)` |
| _text input_ | `try editor.insert("string")` |