idet-core
Backend-agnostic editing logic for a text editor: word autocomplete, line moves,
word swaps, indentation edits and bracket-pair matching. No dependencies, no I/O —
every function takes a &str and a character index and returns a new string and
cursor position (or a range). Drive it from a terminal UI, an egui widget, or
anything else that owns the text buffer and the keybindings.
Built for idet, a Micro-like terminal editor,
and its egui-based sibling idet-gui, sharing one editing core between two very
different frontends.
Modules
completion— word collection and prefix/whole-word matching for autocomplete (collect_words,current_word,matches).edits— insertion, indentation and newline-with-autoindent, plus line-start/line-end lookup (insert,newline_indent,indent_line,dedent_line,line_start_char,line_end_char).lineops— moving the current line up or down, and translating between character offsets and line/column coordinates (move_line,line_column,cursor_at).wordops— swapping the word at the cursor with an adjacent word (swap).brackets— finding the matching bracket for(),[]or{}at or near the cursor (find_matching_bracket).
Design
Every operation is a pure function over character indices, not byte offsets — callers don't need to think about UTF-8 boundaries. Multi-cursor editing is the caller's responsibility: run the same operation once per cursor, in descending position order, shifting later cursors by the delta each edit produces.