Move cursor movement logic from EditorCore/Cursor into Configuration layer.
This prepares the codebase for a Turing-complete scripting DSL by keeping
EditorAction minimal (only absolute MoveCursor { x, y }) and having the
scripting layer compute all movement targets via BufferQuery.
- Add BufferQuery trait for read-only buffer access
- Remove CursorMovement enum, replace with MoveCursor { x, y }
- Simplify Cursor to just hold position (remove move_cursor method)
- Configuration now computes movement targets using BufferQuery
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
5.9 KiB
Minimal EditorAction Architecture
This document describes the architectural approach for making pane-editor highly scriptable by keeping EditorAction minimal and pushing movement logic into the scripting/configuration layer.
Goals
- Emacs-level scriptability via a Turing-complete DSL (non-Lisp)
- Vim-like UX - modal, light, fast
- Stable core - EditorCore changes rarely, all "smarts" live in scripts
Architecture Overview
┌─────────────────────────────────────────────────────┐
│ Scripting Layer (Configuration / future DSL) │
│ - Keybindings │
│ - Movement definitions (what is a "word"?) │
│ - Custom commands │
│ - Plugins │
│ │
│ [reads via BufferQuery] [writes via actions] │
└──────────┬─────────────────────────────────────────┬┘
│ │
▼ ▼
┌─────────────────────┐ ┌─────────────────────────┐
│ BufferQuery trait │ │ EditorAction │
│ │ │ │
│ - cursor() │ │ - MoveCursor { x, y } │
│ - line_count() │ │ - InsertCharacter(ch) │
│ - line_len(y) │ │ - DeleteChar │
│ - char_at(x, y) │ │ - SetMode(Mode) │
│ │ │ - etc. │
└──────────┬──────────┘ └────────────┬────────────┘
│ │
▼ ▼
┌─────────────────────────────────────────────────────┐
│ EditorCore │
│ - Buffers (Rope storage) │
│ - Cursor positions (just x, y - no logic) │
│ - Mode state │
│ - Undo history (future) │
│ │
│ (Dumb state container - no movement logic) │
└─────────────────────────────────────────────────────┘
Key Design Decisions
1. EditorAction is Minimal
EditorAction::MoveCursor takes absolute { x, y } coordinates only. There is no NextWord, PrevLine, or EndOfLine variant. The scripting layer computes target positions using BufferQuery and emits absolute moves.
pub enum EditorAction {
MoveCursor { x: usize, y: usize },
InsertCharacter(char),
DeleteChar,
SetMode(Mode),
// ...
}
2. BufferQuery Exposes Read-Only State
The scripting layer needs to inspect buffer contents to compute movement targets:
pub trait BufferQuery {
fn cursor(&self) -> (usize, usize);
fn line_count(&self) -> usize;
fn line_len(&self, y: usize) -> usize;
fn char_at(&self, x: usize, y: usize) -> Option<char>;
}
3. Cursor is a Dumb Position Holder
Cursor stores (x, y) and nothing else. No move_cursor() method. All movement computation happens in the scripting layer.
4. Configuration Gets Query Access
Configuration::get_editor_action() receives a &dyn BufferQuery so it can compute movement targets:
impl Configuration {
pub fn get_editor_action(
&self,
input: Input,
mode: Mode,
buffer: Option<&dyn BufferQuery>,
) -> Option<EditorAction>;
}
Example: How "j" (move down) Works
- User presses
jin Normal mode EditorCore::send_input(Input::Character('j'))is called- EditorCore passes the active buffer (as
&dyn BufferQuery) to Configuration - Configuration queries
buffer.cursor()→(5, 10)(x=5, y=10) - Configuration queries
buffer.line_count()→100 - Configuration computes:
new_y = min(10 + 1, 100 - 1) = 11 - Configuration returns
EditorAction::MoveCursor { x: 5, y: 11 } - EditorCore sets cursor to (5, 11)
Example: How "w" (next word) Will Work
- User presses
win Normal mode - Configuration queries buffer for current position and text
- Configuration's word-finding logic (eventually defined in DSL) scans forward:
- Skip current word characters
- Skip non-word characters
- Return position of next word start
- Configuration returns
EditorAction::MoveCursor { x: new_x, y: new_y }
The word definition (what characters are "word" vs "punctuation") lives entirely in the scripting layer, not in EditorCore.
Benefits
- EditorCore is stable: Adding new movement types never requires EditorCore changes
- Full scriptability: DSL can define arbitrarily complex movements
- Configurable word definitions: "word" means whatever the user's config says
- Testable: Movement logic can be unit tested without EditorCore
- Frontend agnostic: EditorCore remains decoupled from input handling
Migration Path
- Replace
CursorMovementenum withMoveCursor { x, y } - Add
BufferQuerytrait, implement onTextBuffer - Move movement logic from
Cursor::move_cursor()toConfiguration - Simplify
Cursorto just hold position - (Future) Replace Configuration's Rust code with DSL interpreter