hone-editor
Package: @honeide/editor — embeddable code editor. 353 tests.
cd hone-editor && bun test
The editor is structured in three layers: core (platform-independent logic), view-model (reactive state bridge), and native (Rust FFI per platform).
Core
buffer/
Piece table backed by a rope with a line index. TextBuffer wraps rope internals with a clean API for editing and querying.
cursor/
Multi-cursor management. CursorManager handles primary and secondary cursors with merging, sorting, selection ranges, and word boundary detection.
history/
UndoManager with time-based coalescing (500ms window, max depth 10000). Each operation records: edits, deleted texts, cursor state before and after. Supports computeInverseEdits for redo.
viewport/
ViewportManager for virtual scrolling. Computes visible line range with a 10-line buffer zone. Tracks hidden lines from code folding. Includes ScrollController and LineHeightCache.
tokenizer/
SyntaxEngine via Lezer parser integration. Incremental tokenization — only re-tokenizes affected regions after edits. Token theme resolution maps parser tokens to editor colors. KeywordSyntaxEngine serves as a fallback when no grammar is available.
Bundled grammars: TypeScript, HTML, CSS, JSON, Markdown, Python, Rust, C++
search/
SearchEngine supporting literal and regex modes, chunked for large files. Replace supports regex capture group expansion. IncrementalSearch powers the live find widget.
folding/
Two folding strategies:
- Indent-based — fallback for languages without a grammar
- Syntax-based — uses Lezer parse tree
FoldState tracks collapsed ranges.
diff/
Myers diff algorithm with O(ND) complexity. DiffResult contains hunks typed as add, delete, or modify. Utilities: mergeAdjacentHunks, splitHunk, navigateHunks. Supports inline character-level diff within hunks.
document/
EditorDocument combines TextBuffer with metadata: URI, languageId, version, isDirty, encoding, and line-ending detection. EditBuilder provides a transaction API for batching edits.
commands/
CommandRegistry maps string IDs to handler functions. Five command modules:
- Editing (insert, delete, indent)
- Navigation (move, scroll, go-to)
- Selection (select word, line, all)
- Clipboard (cut, copy, paste)
- Multicursor (add cursor above/below, select occurrences)
lsp-client/
LSPClient wrapping JSON-RPC transport. Typed methods for completion, hover, diagnostics, and code actions. Manages the initialize/initialized lifecycle. ServerCapabilityChecker queries what the server supports.
dap-client/
DAPClient for debug sessions. Supports launch/attach configurations, breakpoint management, stepping (into/over/out), stack frame inspection, and variable evaluation.
snippets/
Snippet template processing with tab stops, placeholders, and variable expansion. Language-specific snippet registries.
View-Model
Reactive state bridge between core subsystems and rendering.
EditorViewModel is the main orchestrator. It connects buffer, cursor, viewport, tokenizer, search, and folding into a unified state that the native layer consumes.
Sub-models:
| Model | Responsibility |
|---|---|
CursorState | Cursor positions and selection visuals |
Decorations | Inline and margin decorations |
DiffViewModel | Side-by-side and inline diff state |
FindWidget | Find/replace UI state |
GhostText | Inline completion preview |
Gutter | Line numbers, fold markers, breakpoints |
LineLayout | Line wrapping and layout metrics |
Minimap | Document overview rendering state |
Overlays | Hover cards, autocomplete popups, signature help |
EditorTheme | Token and UI color resolution |
Native (Rust FFI)
NativeEditorFFI interface defines 93+ FFI functions covering rendering, input handling, events, font metrics, and color management.
Key components:
NativeRenderCoordinator— orchestrates rendering calls to the platform layerTouchInputHandler— processes touch events for mobile platforms- Word wrap computation
Six platform crates:
| Platform | Rendering Stack |
|---|---|
| macOS | Metal, CoreGraphics, CoreText |
| iOS | UIKit |
| Windows | Direct2D, DirectWrite |
| Linux | Cairo, Pango |
| Android | Native .so |
| Web | WASM |