Skip to content

Files: undo and redo keyboard shortcuts do not work in the editor #398

Open

Description

@mubeda

Summary

(measured: owner report, 19 Nov 2026) In the Files editor, undo only works by pressing the Undo button. The usual keyboard shortcuts should also work: Undo with Ctrl/Cmd+Z, Redo with Shift+Ctrl/Cmd+Z and Ctrl+Y (Windows).

(measured) The toolbar already advertises those shortcuts in its tooltips, but the Files surface only binds Ctrl/Cmd+S. Undo and Redo are click handlers on the session or the rich editor. This was not reproduced at runtime in this write-up.

(measured) Verified at 3b74079286c8eab8dfa24c59c3843232bd9b633b (origin/main). Every path:line below refers to this SHA. No app or test was run. Production data was not read.

Current behavior

  • Opening a file in Files shows a toolbar with Save, Undo and Redo (FileEditorToolbar.tsx:152–185). Tooltips say Undo (Ctrl/Cmd+Z) and Redo (Shift+Ctrl/Cmd+Z). The buttons call onUndo / onRedo on click only. Tests click the buttons; they do not dispatch those chords (FileEditorToolbar.test.tsx).
  • The panel wires those clicks to the rich editor in the rendered Markdown view, otherwise to the source session (FilePreviewPanel.tsx:1068–1125): activeRichEditor.undo() or session.undo().
  • Source editing uses Pierre (Editor from @pierre/diffs/edit), which keeps its own undo history (fileEditingSession.ts:11, :417–427). Pierre lives in a shadow root (diffs-container).
  • Rendered Markdown uses TipTap with StarterKit (richMarkdownExtensions.ts:174–184). (inferred) StarterKit’s History extension usually binds Mod-Z / Mod-Shift-Z inside that editor, unless something else takes the event first. Ctrl+Y is not mentioned in the Files toolbar.
  • Save already has a dedicated hook, useFileSaveShortcut, on the file-surface container, capture phase, so it wins before Pierre’s handlers (useFileSaveShortcut.ts:32–56). It is used from FilePreviewPanel and RichMarkdownView. There is no matching undo/redo hook. A repo search for key === "z", Mod-z, or useFileUndo in apps/web/src found only the toolbar tooltip strings and the Save hook.
  • The only other Files keydown capture is Escape, to dismiss the editor (fileEditorDismissal.ts:42–51). It does not handle Z.
  • The desktop Edit menu is Tauri’s predefined Undo / Redo (apps/desktop/src-tauri/src/window.rs:116–124), with no custom handler. (inferred) On macOS, Cmd+Z often goes to that menu first. Predefined Undo targets native web content, not Pierre’s or TipTap’s own history, so the menu may do nothing or undo the wrong thing.

(guess) The advertised shortcuts do nothing in the source (Pierre) view because they are never bound to session.undo() / redo(). In the rendered view, TipTap may handle them in a browser, but the desktop Edit menu can still steal Cmd+Z on macOS. This is the leading hypothesis; it has not been flipped in a runtime test.

Proposed behavior

  • While focus is in the Files editor surface (source or rendered), Ctrl/Cmd+Z undoes, and Shift+Ctrl/Cmd+Z or Ctrl+Y (Windows) redoes, using the same history as the toolbar buttons (session or activeRichEditor).
  • The chords should preventDefault the same way Save does, so the browser or the desktop Edit menu cannot run a different undo.
  • Disabled Undo / Redo (nothing to undo) should be a no-op, matching the disabled buttons.
  • (inferred) Prefer a useFileUndoShortcut next to useFileSaveShortcut, capture phase on the same surface, so Pierre’s shadow root does not swallow the chord. On the desktop, Edit menu Undo/Redo should drive that same history when the Files editor is focused, or the menu accelerators must not block the web handler.

Open questions

  1. Does the failure happen in both the source view and the rendered Markdown view, or only in one? Recommended: fix both, and add a test for each.
  2. Should Windows Ctrl+Y redo as well as Shift+Ctrl+Z? Recommended: yes; the toolbar currently only mentions Shift+Ctrl/Cmd+Z.
  3. Should the macOS/desktop Edit menu Undo and Redo run the Files editor history when that surface is focused? Recommended: yes, or the accelerators must not steal the chord.

Acceptance criteria

  • In the Files source editor, after a typable edit, Ctrl+Z (Windows/Linux) and Cmd+Z (macOS) undo it; the matching redo shortcuts restore it. The toolbar buttons still work and stay in sync (canUndo / canRedo).
  • The same shortcuts work in the rendered Markdown editor after a formatting or text edit.
  • Ctrl+Y redos on Windows. Shift+Ctrl/Cmd+Z redos on every platform.
  • Focus outside the Files editor is unchanged (chat, other panels). Save (Ctrl/Cmd+S) still works.
  • Focused tests dispatch the chords (not only button clicks). Desktop coverage should include the Edit menu path or a documented reason it is equivalent. Usual repo gates pass: focused tests, vp check, typecheck, and cargo fmt / Clippy if Rust menu wiring changes.

Related

  • Not a duplicate of any open or closed issue found for Files keyboard undo/redo.
  • #342 (closed): added the rendered Markdown toolbar, including Undo and Redo buttons. It did not bind the advertised keyboard shortcuts.
  • #180 (closed): disk-change overwrite; mentions Undo in passing, different bug.
  • #394 (closed): mentions a settings keybinding-save finding, not the Files editor.

Activity

  1. added
    bugSomething is broken or behaving incorrectly.
    needs-triageIssue needs maintainer review and initial categorization.
    on Nov 20, 2026
  2. mubeda commented on Nov 22, 2026

    @mubeda
    OwnerAuthor

    Diagnosis and fix, measured in the packaged desktop app on the three platforms.

    Cause. On macOS the predefined Edit menu items Undo and Redo took Cmd+Z and Shift+Cmd+Z before the page saw them, so the Files editor's own history never ran. Windows and Linux deliver the chord to the page; there the editor already handled it.

    Fix. On macOS the Edit menu now has its own Undo and Redo items with the same shortcuts. When the focus is in the main window's web view, they run the Files editor's history (or the browser's own undo outside the editor); anywhere else, such as a native text field or a sheet, they send the standard undo or redo action. Undo during text composition (an input method or a dead key) is left to the system. The toolbar tooltips name the shortcuts that work in each view.

    Packaged results (apps/desktop/e2e/specs/files-undo-shortcuts.e2e.ts, Profiler on):

    Platform Real keyboard and menu input Default run
    macOS 40 of 40 (4 pending: the 2 preview cells, and 2 terminal redo cells that do not apply on macOS) 7 of 7
    Windows 48 of 48 9 of 9
    Linux 32 of 32 9 of 9

    Not covered: undo inside the preview web view. Those cells stay pending because the test page does not load in the preview during the run; the window and focus checks that route the shortcut have unit tests.

    Related fixes in the same pull request: #408 (Ctrl+Z in plain text fields on Linux), #409 (the packaged tests no longer run tools installed on the machine), #410 (native objects released after each web view call on macOS).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is broken or behaving incorrectly.needs-triageIssue needs maintainer review and initial categorization.size:S

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions