Skip to content

Commit 60a574d

Browse files
Fix undo/redo
1 parent 8409f70 commit 60a574d

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

‎src/morgul/app.py‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,15 +408,28 @@ def keyPressEvent(self, event: QKeyEvent) -> None:
408408
Qt.KeyboardModifier.NoModifier,
409409
Qt.KeyboardModifier.KeypadModifier,
410410
}
411+
# QPlainTextEdit consumes Ctrl+Z / Ctrl+Y / Ctrl+Shift+Z internally (its
412+
# own undo stack is disabled via setUndoRedoEnabled(False)), which would
413+
# swallow the app-level Undo/Redo QAction shortcuts. Route them to the
414+
# session-persisted history ourselves.
415+
host = self._main_window()
416+
ctrl = bool(mods & Qt.KeyboardModifier.ControlModifier)
417+
if ctrl and host is not None and event.key() == Qt.Key.Key_Z:
418+
if mods & Qt.KeyboardModifier.ShiftModifier:
419+
host._redo() # ruff: ignore[private-member-access]
420+
else:
421+
host._undo() # ruff: ignore[private-member-access]
422+
return
423+
if ctrl and host is not None and event.key() == Qt.Key.Key_Y:
424+
host._redo() # ruff: ignore[private-member-access]
425+
return
411426
if event.key() == Qt.Key.Key_Insert and no_mods:
412427
host = self._main_window()
413428
if host is not None:
414429
host.toggle_replace_mode()
415430
return
416431

417432
text = event.text()
418-
ctrl = bool(mods & Qt.KeyboardModifier.ControlModifier)
419-
host = self._main_window()
420433
replace_on = host is not None and host.replace_mode
421434
if replace_on and text and text.isprintable() and not ctrl:
422435
cursor = self.textCursor()

0 commit comments

Comments
 (0)