- Improve text input/event batching - Enhance debugging with optional instrumentation - Begin implementation of non-linear undo tree structure.
9.2 KiB
9.2 KiB
Context recap
- The undo system is now tree‑based with batching rules and
KTE_UNDO_DEBUGinstrumentation hooks already present inUndoSystem.{h,cc}. - GUI path uses SDL; printable input now flows exclusively via
SDL_TEXTINPUTtoCommandId::InsertText, while control/meta/movement (incl. Backspace/Delete/Newline and k‑prefix) come fromSDL_KEYDOWN. - Commit boundaries must be enforced at well‑defined points (movement, non‑editing commands, newline, undo/redo, etc.).
Status summary (2025‑12‑01)
- Input‑path unification: Completed.
GUIInputHandler.ccroutes all printable characters throughSDL_TEXTINPUT → InsertText. Newlines originate only fromSDL_KEYDOWN → Newline. CR/LF are filtered out ofSDL_TEXTINPUTpayloads. Suppression rules prevent strayTEXTINPUTafter meta/prefix/universal‑argument flows. Terminal input path remains consistent. - Tests:
test_undo.ccexpanded to cover branching behavior, UTF‑8 insertion, multi‑line newline/join, and typing batching. All scenarios pass. - Instrumentation:
KTE_UNDO_DEBUGhooks exist inUndoSystem.{h,cc}; a CMake toggle has not yet been added. - Commit boundaries: Undo/Redo commit boundaries are in place; newline path commits immediately by design. A final audit pass across movement/non‑editing commands is still pending.
- Docs: This status document updated. Further docs (instrumentation how‑to and example traces) remain pending in
docs/undo.md/docs/undo-roadmap.md.
Objectives
- Use the existing instrumentation to capture short traces of typing/backspacing/deleting and undo/redo.
- Unify input paths (SDL
KEYDOWNvsTEXTINPUT) and lock down commit boundaries across commands. - Extend tests to cover branching behavior, UTF‑8, and multi‑line operations.
Plan of action
-
Enable instrumentation and make it easy to toggle
- Add a CMake option in
CMakeLists.txt(root project):option(KTE_UNDO_DEBUG "Enable undo instrumentation logs" OFF). - When ON, add a compile definition
-DKTE_UNDO_DEBUGto all targets that include the editor core (e.g.,kte,kge, and test binaries). - Keep the default OFF so normal builds are quiet; ensure both modes compile in CI.
- Add a CMake option in
-
Capture short traces to validate current behavior
- Build with
-DKTE_UNDO_DEBUG=ONand run the GUI frontend:- Scenario A: type a contiguous word, then move cursor (should show
Begin(Insert)+ multipleAppend, singlecommitat a movement boundary). - Scenario B: hold backspace to delete a run, including backspace batching (prepend rule); verify
Begin(Delete)with prependedAppendbehavior, singlecommit. - Scenario C: forward deletes at a fixed column (anchor batching); expected single
Begin(Delete)with same column. - Scenario D: insert newline (
Newlinenode) and immediately commit; type text on the next line; undo/redo across the boundary. - Scenario E: undo chain and redo chain; then type new text and confirm redo branch gets discarded in logs.
- Scenario A: type a contiguous word, then move cursor (should show
- Save representative trace snippets and add to
docs/undo.mdordocs/undo-roadmap.mdfor reference.
- Build with
-
Input‑path unification (SDL
KEYDOWNvsTEXTINPUT) — Completed 2025‑12‑01- In
GUIInputHandler.cc:- Ensure printable characters are generated exclusively from
SDL_TEXTINPUTand mapped toCommandId::InsertText. - Keep
SDL_KEYDOWNfor control/meta/movement, backspace/delete, newline, and k‑prefix handling. - Maintain suppression of stray
SDL_TEXTINPUTimmediately following meta/prefix or universal‑argument collection so no accidental text is inserted. - Confirm that
InsertTextpath never carries"\n"; newline must only originate fromKEYDOWN→CommandId::Newline.
- Ensure printable characters are generated exclusively from
- If the terminal input path exists, ensure parity: printable insertions go through
InsertText, control via key events, and the same commit boundaries apply. - Status: Implemented. See
GUIInputHandler.ccchanges; tests confirm parity with terminal path.
- In
-
Enforce and verify commit boundaries in command execution — In progress
- Audit
Command.ccand ensureu->commit()is called before executing any non‑editing command that should end a batch:- Movement commands (left/right/up/down/home/end/page).
- Prompt accept/cancel transitions and mode switches (search prompts, replace prompts).
- Buffer/file operations (open/switch/save/close), and focus changes.
- Before running
UndoorRedo(already present).
- Ensure immediate commit at the end of atomic edit operations:
Newlineinsertion and line joins (Deleteof newline when backspacing at column 0) should createUndoType::Newlineand commit immediately (parts are already implemented; verify all call sites).- Pastes should be a single
Paste/Insertbatch per operation (depending on current design).
- Audit
-
Extend automated tests (or add them if absent) — Phase 1 completed
- Branching behavior ✓
- Insert
"abc", undo twice (back to"a"), insert"X", assert redo list is discarded, and new timeline continues withaX. - Navigate undo/redo along the new branch to ensure correctness.
- Insert
- UTF‑8 insertion and deletion ✓
- Insert
"é漢"(multi‑byte characters) viaInsertText; verify buffer content and that a single Insert batch is created. - Undo/redo restores/removes the full insertion batch.
- Backspace after typed UTF‑8 should remove the last inserted codepoint from the batch in a single undo step ( current semantics are byte‑oriented in buffer ops; test to current behavior and document).
- Insert
- Multi‑line operations ✓
- Newline splits a line: verify an
UndoType::Newlinenode is created and committed immediately; undo/redo round‑trip. - Backspace at column 0 joins with previous line: record as
Newlinedeletion (viaUndoType::Newlineinverse); undo/redo round‑trip.
- Newline splits a line: verify an
- Typing and deletion batching ✓ (typing) / Pending (delete batching)
- Typing a contiguous word (no cursor moves) yields one
Insertnode with accumulated text. - Forward delete at a fixed anchor column yields one
Deletebatch. (Pending test) - Backspace batching uses the prepend rule when the cursor moves left. (Pending test)
- Typing a contiguous word (no cursor moves) yields one
- Place tests near existing test suite files (e.g.,
tests/test_undo.cc) or create them if not present. Prefer usingBuffer+UndoSystemdirectly for tight unit tests; add higher‑level integration tests as needed.
- Branching behavior ✓
-
Documentation updates — In progress
- In
docs/undo.mdanddocs/undo-roadmap.md:- Describe how to enable instrumentation (
KTE_UNDO_DEBUG) and an example of trace logs. - List batching rules and commit boundaries clearly with examples.
- Document current UTF‑8 semantics (byte‑wise vs codepoint‑wise) and any known limitations.
- Describe how to enable instrumentation (
- Current status: this
undo-state.mdupdated; instrumentation how‑to and example traces pending.
- In
-
CI and build hygiene — Pending
- Default builds:
KTE_UNDO_DEBUGOFF. - Add a CI job that builds and runs tests with
KTE_UNDO_DEBUG=ONto ensure the instrumentation path remains healthy. - Ensure no performance regressions or excessive logging in release builds.
- Default builds:
-
Stretch goals (optional, time‑boxed) — Pending
- IME composition: confirm that
SDL_TEXTINPUTbehavior during IME composition does not produce partial/broken insertions; if needed, buffer composition updates into a single commit. - Ensure paste operations (multi‑line/UTF‑8) remain atomic in undo history.
- IME composition: confirm that
How to run the tests
- Configure with
-DBUILD_TESTS=ONand build thetest_undotarget. Run the produced binary (e.g.,./test_undo). The test prints progress and uses assertions to validate behavior.
Deliverables
- CMake toggle for instrumentation and verified logs for core scenarios. (Pending)
- Updated
GUIInputHandler.ccsolidifyingKEYDOWNvsTEXTINPUTseparation and suppression rules. (Completed) - Verified commit boundaries in
Command.ccwith comments where appropriate. (In progress) - New tests for branching, UTF‑8, and multi‑line operations; all passing. (Completed for listed scenarios)
- Docs updated with how‑to and example traces. (Pending)
Acceptance criteria
Current status (2025‑12‑01) vs acceptance criteria
- Short instrumentation traces match expected batching and commit behavior for typing, backspace/delete, newline, and undo/redo. — Pending (instrumentation toggle + capture not done)
- Printable input comes exclusively from
SDL_TEXTINPUT; no stray inserts after meta/prefix/universal‑argument flows. — Satisfied (GUI path updated; terminal path consistent) - Undo branching behaves correctly; redo is discarded upon new commits after undo. — Satisfied (tested)
- UTF‑8 and multi‑line scenarios round‑trip via undo/redo according to the documented semantics. — Satisfied (tested)
- Tests pass with
KTE_UNDO_DEBUGboth OFF and ON. — Pending (no CMake toggle yet; default OFF passes)