Skip to content

feat: undo/redo for the SQL editor#22

Merged
muk2 merged 1 commit intomainfrom
feature/issue-15-undo-redo
Feb 19, 2026
Merged

feat: undo/redo for the SQL editor#22
muk2 merged 1 commit intomainfrom
feature/issue-15-undo-redo

Conversation

@muk2
Copy link
Owner

@muk2 muk2 commented Feb 18, 2026

Summary

Implements full undo/redo functionality for the SQL editor, addressing #15.

  • Ctrl+Z — undo last edit
  • Ctrl+Shift+Z or Ctrl+Y — redo
  • Intelligent grouping — consecutive character inserts are grouped into a single undo unit, consecutive deletes are grouped, while newlines/paste/cut create separate undo points
  • Cursor position restored on undo/redo
  • Max 500 undo operations (configurable)
  • set_text() and clear() reset undo history (loading from history/clearing editor starts fresh)

Edit Grouping Rules

Action Grouping
Typing characters Grouped until a different action type
Newline (Enter) New undo unit
Backspace/Delete Grouped together
Paste Single undo unit
Cut Single undo unit
Delete selection Single undo unit

Changes

File Change
src/editor/buffer.rs Added UndoHistory, BufferSnapshot, UndoActionType; save_undo(), undo(), redo() methods; integrated undo recording into all mutation methods
src/ui/app.rs Wired Ctrl+Z, Ctrl+Shift+Z, Ctrl+Y keybindings
src/ui/components.rs Updated help overlay with undo/redo keybindings

Test plan

  • All 137 tests pass (13 new undo/redo tests)
  • Clippy clean
  • cargo fmt clean
  • Verify Ctrl+Z undoes typing
  • Verify Ctrl+Shift+Z / Ctrl+Y redoes
  • Verify consecutive typing is grouped into one undo
  • Verify newlines create separate undo points
  • Verify paste is a single undo unit
  • Verify cursor is restored after undo/redo

Closes #15

🤖 Generated with Claude Code

Implement undo/redo with Ctrl+Z / Ctrl+Shift+Z (or Ctrl+Y) in the
query editor. Uses snapshot-based undo with intelligent grouping:
consecutive character inserts/deletes are grouped into single undo
units, while newlines, paste, and selection operations create
separate undo points. Max undo depth is 500 operations.

- Added UndoHistory with snapshot-based undo/redo stacks
- Consecutive same-type edits (insert/delete) are grouped
- Newlines, paste, cut, and selection deletes create new groups
- set_text() and clear() reset undo history
- Cursor position is restored on undo/redo
- 13 new unit tests for undo/redo behavior
- Help overlay updated with new keybindings

Closes #15

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@muk2 muk2 merged commit 4e73951 into main Feb 19, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Undo/Redo for the SQL editor

1 participant