Skip to content

editor: T-112 spec, VS Code typing undo groups - #46

Merged
shubhook merged 3 commits into
mainfrom
t3/t112-vscode-undo-groups-spec
Nov 29, 2026
Merged

shubhook merged 3 commits into
mainfrom
t3/t112-vscode-undo-groups-spec

Conversation

@shubhook

@shubhook shubhook commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner

Task: T-112, tasks/112-vscode-undo-groups.md

PRD: ED-2, ED-4

What changed

This is the spec PR for T-112: the task file, the interface as stubs, and the acceptance tests. Nothing is implemented. Written against main at 3566348.

In VS Code mode, a run of typing will undo in one step. The editor decides where a step ends: a pause, a cursor move, a switch between typing and deleting, Enter, a deleted line break, a paste, undo and redo. Vim's groups don't change.

  • Interface (crates/helm-editor/src): UndoGrouping (Explicit, the default, and Typing), Editor::set_undo_grouping, undo_grouping, set_time(Duration) and TYPING_PAUSE (1 s), and Keymap::with_undo_grouping and undo_grouping. Methods have todo!() bodies. UndoGrouping and TYPING_PAUSE are plain data and work now. The rules are in the "Typing groups (T-112)" section of Editor's type docs. Updated doc comments say how dispatch, dispatch_in, vscode::keymap(), Clone for Editor, end_undo_group and in_undo_group will change. Their code is unchanged in this PR.
  • How time arrives. helm-ui calls Editor::set_time before each key. helm-editor never reads a clock. A timestamp field on KeyEvent would break struct literals in four protected test files and benches/vim.rs.
  • Acceptance tests: three new files with 39 tests, each #[ignore = "T-112: not implemented yet"]. They are typing_groups.rs (25), vscode_undo.rs (10) and typing_group_properties.rs (4 proptest properties, 256 cases each). No existing test file changes.
  • Against the stubs, cargo test -p helm-editor --no-fail-fast -- --ignored fails all 39.
  • Khakha's answers (c53b211): the task file records them, quoted below. No stub, doc comment or test changed.

Throwaway check

I checked the tests against a throwaway implementation that isn't in this PR:

  • All 39 new tests pass on it, and so do all 443 helm-editor tests, so no T-101 to T-114 test changes behaviour.
  • The four properties pass at 20,000 cases each.
  • I ran eleven wrong versions of the throwaway against the new files. Ten failed at least one test, most of them several: no move rule, moves found by comparison only, no pause rule, the pause counted from the step's first edit, Enter joining the typing before it, no line-break rule, kinds ignored, a grouping change that keeps an open group, dispatch_in not setting the grouping, and an other edit joining the typing step.
  • The eleventh passed every test, because it behaves exactly like the original: it leaves a group open after an other edit, and an other edit already ends the typing group before it applies.

For the council

This PR gets one council round, aimed at the tests: do they test what ED-2 and ED-4 ask for, and could a wrong implementation pass them? The property oracle reads three facts off a twin editor under Explicit grouping: whether an edit applied, whether a motion moved, and whether a delete lowered the line count. The task file says why properties 2 and 4 leave out lone CRs.

VS Code's docs and Helm proposals

VS Code's public docs don't describe when typing splits into undo steps. They only list undo, redo, cursorUndo and the paste action. So every boundary rule is a Helm proposal, and Khakha's answers below settle them for Helm. Where VS Code's MIT-licensed source agrees, the task file says so.

Protected paths

tasks/112-vscode-undo-groups.md is under tasks/**. Khakha added the approved-protected label, and the protected-paths check passes on c53b211. The new test files are new files, not edits to existing ones.

Dependencies, unsafe, threading

No new dependency. No unsafe. No threads. No Cargo.toml or Cargo.lock change.

Open questions for Khakha: answered

Khakha answered all seven and kept the spec's choice on each. So the interface and the tests stand as written, and the implementation can start. Khakha's answers, as written:

  1. Keep the pause rule. TYPING_PAUSE is 1 s.
  2. Yes, every cursor move ends the open undo step.
  3. Yes, Enter starts a new step, and typing right after it joins that step.
  4. Yes, the keymap carries the grouping, and the dispatcher applies it. helm-ui does not set it after each switch.
  5. Word-by-word steps go to a later task.
  6. An edit with nothing to do keeps the open step, as specified.
  7. TYPING_PAUSE stays a constant.

The questions as asked. Questions 1 to 4 blocked the implementation, and 5 to 7 had defaults:

  1. Keep the pause rule, and at what length? (answered: kept, 1 s) I proposed 1 s. VS Code's docs describe no pause, and its cursor code has no undo timer.
  2. Should every move end the step? (answered: yes) VS Code's cursor controller doesn't reset on a move, so VS Code may join ab, Left, c.
  3. Enter starts a step, and typing after it joins. (answered: yes) This matches VS Code's source.
  4. The keymap carries the grouping and the dispatcher applies it. (answered: yes) The alternative was helm-ui calling set_undo_grouping after each switch.
  5. Word-by-word steps, VS Code's apparent space rule (answered: a later task).
  6. An edit with nothing to do keeps the step (answered: as specified).
  7. TYPING_PAUSE as a constant, or a field on UndoGrouping::Typing for ST-1 (answered: a constant).

Commands run

On 1a54b47. c53b211 changes only tasks/112-vscode-undo-groups.md, and CI passed on it.

$ cargo build --workspace
    Finished `dev` profile, exit 0
$ cargo test --workspace
    exit 0: 584 passed, 0 failed, 39 ignored (the new T-112 tests)
$ cargo fmt --all --check
    exit 0
$ cargo clippy --workspace --all-targets -- -D warnings
    Finished, exit 0
$ cargo bench -p helm-bench
    exit 0, local: all 29 existing benchmarks ran

This PR adds no benchmark and changes no code path that a benchmark runs: the stubs aren't called from existing code. So no speed number is claimed. The implementation PR adds the three typing/ benchmarks that the task file lists.

CI benchmarks

All numbers are bench-compare's fastest of three medians, not means, against base 3566348.

On c53b211 (run 46165336874), every benchmark is within the gate: "No benchmark regressed past its budget." Changes range from −6.90% (amend/type_100_chars_undo_10mb) to +1.86% (vim/visual_w_d_undo_1000_cursors_10mb). vim_objects/di_paren_no_pair_10mb measured 1.076 ms on base and 1.075 ms on head, −0.06%.

On 1a54b47 (run 46161217339), the first attempt failed the gate on one benchmark: vim_objects/di_paren_no_pair_10mb, 899.19 µs on base and 1.070 ms on head, +19.03%. Every other benchmark was within ±3.4%, apart from encoding/decode_encode_bom_10mb, which was 6.55% faster. I ran a controlled comparison before treating the 19% as noise:

  • Same instructions. Built in release for x86_64-unknown-linux-gnu, all 427 functions in helm-editor at base have the same instructions at head, find_pair and the rest of the bracket scan included. I compared the emitted assembly with symbol hashes, label numbers and constant names normalized. Head only adds the five stub functions.
  • Same layout. In the linked aarch64 vim_objects benchmark binaries (local), every function sits at the same address. The only instruction differences are 59 add immediates, each 3 bytes higher in head, where read-only data moved. They are in 28 Editor and vim methods. None of them is find_pair or the code under it, the bracket scan the benchmark times.
  • No local gap. I ran the two built benchmark binaries directly, alternating in ABBA order, three times (local, criterion means). Head averaged 910.5 µs (971, 918, 916, 896, 874 and 888 µs). Base averaged 915.0 µs (921, 951, 873, 922, 875 and 948 µs).
  • CI rerun passes. I reran bench-shard (cursor vim_objects). di_paren_no_pair_10mb measured 893.75 µs on base and 916.62 µs on head, +2.56%, and bench-compare reported "No benchmark regressed past its budget."
  • A noisy benchmark. It moves a lot between CI runners in earlier PRs. On PR editor: T-114, follow up Khakha's answers on PR #42 #45, head ran at 752.52 µs on one run and 1.128 ms on another.

Outside sources

  • VS Code docs, read for what they say about undo (nothing beyond the keybindings): Basic editing, Key bindings, Default keyboard shortcuts.
  • VS Code's MIT-licensed source on main, read to understand its behaviour only, with no code copied: src/vs/editor/common/cursorCommon.ts, cursor/cursor.ts, cursor/cursorTypeOperations.ts, cursor/cursorDeleteOperations.ts, and part of cursor/cursorTypeEditOperations.ts.
  • No Zed, Helix or other Vim emulation was read.

Agent and model

Claude Code, model Claude Opus 5.5 (claude-opus-5-5). Neither changed during the thread.

UndoGrouping, Editor::set_undo_grouping, undo_grouping, set_time and
TYPING_PAUSE, and Keymap::with_undo_grouping and undo_grouping, with
todo!() bodies and the rules in Editor's type docs. Three new test
files, 39 tests, each ignored until the implementation lands.

Refs: T-112, ED-2, ED-4
@shubhook
shubhook marked this pull request as ready for review November 28, 2026 16:26
@shubhook shubhook added the approved-protected Khakha approves a change to a protected path. Agents never add or remove it. label Nov 28, 2026
All seven keep the spec's choice, so the interface and tests stand.

Refs: T-112, ED-2, ED-4
@shubhook
shubhook merged commit 70403b3 into main Nov 29, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved-protected Khakha approves a change to a protected path. Agents never add or remove it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant