Skip to content

refactor: native UndoManager responder chain integration#864

Closed
datlechin wants to merge 5 commits intomainfrom
refactor/undo-responder-chain
Closed

refactor: native UndoManager responder chain integration#864
datlechin wants to merge 5 commits intomainfrom
refactor/undo-responder-chain

Conversation

@datlechin
Copy link
Copy Markdown
Member

Summary

Complete rewrite of the undo/redo architecture from a hacky 6-layer manual routing system to native AppKit responder chain integration.

  • Each QueryTab owns its own DataChangeManager (with its own UndoManager), preserving undo history across tab switches
  • Undo closures capture RowBuffer directly, mutating both change tracking state and resultRows in one step (eliminates UndoResult side-channel)
  • KeyHandlingTableView exposes undoManager through the responder chain — AppKit routes Cmd+Z natively
  • Edit menu shows dynamic action names ("Undo Edit Cell", "Undo Delete Row")
  • Eliminated: UndoResult, UndoAction, applyDataUndo monolith, TabPendingChanges, 6-layer routing chain, manual first-responder fork in menu

Before:

Cmd+Z → Menu fork (firstResponder check)
      → MainContentCommandActions.undoChange()
      → MainContentCoordinator.undoLastChange()
      → RowOperationsManager.undoLastChange()
      → DataChangeManager.undoLastChange() → private undoManager.undo()
      → applyDataUndo() sets lastUndoResult
      → UndoResult returned → applyUndoResult() mutates resultRows

After:

Cmd+Z → AppKit responder chain
      → KeyHandlingTableView.undoManager (override)
      → DataChangeManager.undoManager
      → registered closure fires (updates state + mutates rows + triggers UI)

42 files changed, -253 lines net

Test plan

  • Edit cell → Cmd+Z undoes → Cmd+Shift+Z redoes
  • Insert row → Cmd+Z removes → Cmd+Shift+Z re-inserts
  • Delete row → Cmd+Z undeletes
  • Switch tabs with unsaved edits, switch back → Cmd+Z still works
  • Edit menu shows "Undo Edit Cell" / "Undo Delete Row" dynamically
  • Edit menu Undo greys out when nothing to undo
  • SQL editor: Cmd+Z undoes text edits (unaffected)
  • Structure tab: Cmd+Z undoes structure changes
  • Quit with unsaved changes: still detects correctly
  • Batch delete rows → Cmd+Z restores all

@datlechin datlechin force-pushed the refactor/undo-responder-chain branch from 3ab3200 to 337d9ef Compare April 26, 2026 08:37
@datlechin datlechin closed this Apr 27, 2026
@datlechin datlechin deleted the refactor/undo-responder-chain branch April 28, 2026 00:59
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.

1 participant