Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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++

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:

  1. Editing (insert, delete, indent)
  2. Navigation (move, scroll, go-to)
  3. Selection (select word, line, all)
  4. Clipboard (cut, copy, paste)
  5. 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:

ModelResponsibility
CursorStateCursor positions and selection visuals
DecorationsInline and margin decorations
DiffViewModelSide-by-side and inline diff state
FindWidgetFind/replace UI state
GhostTextInline completion preview
GutterLine numbers, fold markers, breakpoints
LineLayoutLine wrapping and layout metrics
MinimapDocument overview rendering state
OverlaysHover cards, autocomplete popups, signature help
EditorThemeToken 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 layer
  • TouchInputHandler — processes touch events for mobile platforms
  • Word wrap computation

Six platform crates:

PlatformRendering Stack
macOSMetal, CoreGraphics, CoreText
iOSUIKit
WindowsDirect2D, DirectWrite
LinuxCairo, Pango
AndroidNative .so
WebWASM