Edit titles in their boxes, with vim keys inside the text

Titles are typed right in their boxes on the canvas: the box grows with
the text, the terminal's cursor sits in it (a bar while typing, a block
on the letter with vim keys), and the border turns the insert color.
`i`, `A` and Enter edit at the end, `I` at the start, `cc` and `S` type
the title anew. The document follows the text as it's typed, so the
layout stays current, and the whole edit is one undo step.

Esc gives vim's normal mode inside the text (TextEditor, in ui/): h l w
b e 0 ^ $, f t F T with ; and ,, the d c y operators with any of those
motions or the iw aw i" a" i( a( text objects, x X s S D C Y, r ~, p P,
counts, u and Ctrl-r for the edit's own changes, and `.` for the last
one, typing included. j k gg G and J work on lines, for bodies. It
follows vim where it's quirky too: cw acts like ce, dw stops at the end
of the line, Esc steps back onto the last letter. Keys have two new
tables, `text` and `insert`, and in text an operator takes motions as
targets (`dw`, `c$`, `2d3fx`), which which-key lists.

Rapid entry: after `o`, `O` or `a`, the new idea's title is typed at
once; Enter starts the next idea, Tab puts the one being typed under the
idea above, Shift-Tab takes it out a level, and Enter on an empty idea
stops. An idea left empty goes away without a trace in the undo history
(a group whose edits cancel out leaves no step); a title left empty
comes back as it was. Inside a title, `o` and `O` start a new sibling.

Registers are shared by the whole app, so text yanked in one title
pastes into another; `"a`-`"z` and `"_` work, and `"+` stays inside
cumulus until the app core connects the clipboard.

The mouse while editing: a click in the text moves the text cursor, a
click anywhere else keeps the text and finishes the edit, and a
double-click on a title starts editing at that letter.

`>>` and `<<` now move nodes: under the node above, as its last child,
or out a level, right after the old parent, with counts taking in the
next siblings.

The command line's input became TextInput, line-aware so the editor can
use it for bodies too; bodies themselves get edited in the Note view.
The example's tests type every key above into the app and check the
text and the cursor after each one against what vim does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
skkeyeandClaude Opus 5.5 committed 2026-10-01 17:45:40 -04:00
1 parent 6eedbe0ce2
commit 84aefbecdb
31 files changed
+3289 -341

No files matched your search

+42 -5
View File
@@ -191,10 +191,14 @@ impl KeyEngine {
if self.keys.is_empty() {
// A count takes in the next siblings, as `3dd` takes three
// lines in vim: say exactly how many.
let help = match multiply(*count, self.count).unwrap_or(1) {
1 => "this node, with its branch".to_string(),
2 => "2 nodes: this one and the next sibling, with their branches".to_string(),
many => format!(
let help = match (tables.in_text(), multiply(*count, self.count).unwrap_or(1)) {
(true, 1) => "the line".to_string(),
(true, many) => format!("{many} lines"),
(false, 1) => "this node, with its branch".to_string(),
(false, 2) => {
"2 nodes: this one and the next sibling, with their branches".to_string()
}
(false, many) => format!(
"{many} nodes: this one and the next {} siblings, with their branches",
many - 1
),
@@ -356,7 +360,7 @@ fn next_keys(typed: &[Key], candidates: &[&Binding], tables: &Tables<'_>) -> Vec
mod tests {
use super::*;
use crate::input::bindings::Context;
use crate::input::command::Motion;
use crate::input::command::{Motion, TextObject};
use crate::input::key::parse_keys;
use crate::input::keymap::{DEFAULT_LEADER, Keymap};
@@ -417,6 +421,39 @@ mod tests {
assert_eq!(type_keys(&mut engine, &keymap, "'A"), run(Command::JumpToMark('A'), None, None));
}
#[test]
fn inside_text_motions_are_targets_too() {
let keymap = Keymap::new(DEFAULT_LEADER);
let tables = keymap.tables(&[Context::Text]);
let mut engine = KeyEngine::default();
let mut type_text = |text: &str| {
let keys = parse_keys(text, keymap.leader()).unwrap();
keys.into_iter().map(|key| engine.press(key, &tables)).last().unwrap()
};
let operate = |operator, target, count| run(Command::Operate(operator, target), count, None);
assert_eq!(type_text("dw"), operate(Operator::Delete, Target::Motion(Motion::Next), None));
assert_eq!(type_text("d0"), operate(Operator::Delete, Target::Motion(Motion::LineStart), None));
assert_eq!(type_text("ci\""), operate(Operator::Change, Target::Inside(TextObject::Quotes), None));
assert_eq!(type_text("ya("), operate(Operator::Yank, Target::Around(TextObject::Parens), None));
assert_eq!(
type_text("2d3fx"),
operate(Operator::Delete, Target::Motion(Motion::FindForward('x')), Some(6))
);
assert_eq!(type_text("cc"), operate(Operator::Change, Target::Current, None));
assert_eq!(type_text("x"), operate(Operator::Delete, Target::Motion(Motion::Right), None));
assert_eq!(type_text("rq"), run(Command::ReplaceChar('q'), None, None));
type_text("d");
let hints = engine.hints(&tables).unwrap();
assert_eq!(hints.entries[0], Hint { keys: "d".into(), help: "the line".into(), group: false });
assert!(hints.entries.contains(&Hint { keys: "i".into(), help: "+inside".into(), group: true }));
assert!(hints.entries.contains(&Hint {
keys: "w".into(),
help: "the next word".into(),
group: false
}));
}
#[test]
fn which_key_lists_what_can_follow() {
let keymap = Keymap::new(DEFAULT_LEADER);