Skip to content

fix(viewer): a click on Save leaves the focus in the document, so Ctrl/⌘+Z undoes there - #65

Open
pierreneter wants to merge 1 commit into
mainfrom
fix/save-keeps-focus
Open

pierreneter wants to merge 1 commit into
mainfrom
fix/save-keeps-focus

Conversation

@pierreneter

Copy link
Copy Markdown
Member

What

After a click on Save, Ctrl/⌘+Z did nothing in Word, Excel and PowerPoint documents until the document was clicked again. The Undo button still worked, so the history was intact. Only the keyboard was lost.

Why

The Save button took the focus on a click and had disabled={saving}. A disabled button loses its focus, and here the focus went to <body>, outside the viewer. No handler gets keys from there, so every shortcut did nothing, not only undo.

Saving with Ctrl/⌘+S was not affected, because the focus never left the document.

Fix

In src/react/DocViewer.tsx, the Save button:

  • prevents the default on mousedown, as the toolbar's buttons do. A click leaves the focus, the caret and the selection where they were.
  • uses aria-disabled instead of disabled while it saves. A keyboard user who tabs to Save and presses Enter keeps the focus on the button. saveFile already refuses a second save while one runs.

styles.css gives .de-mode[aria-disabled='true'] the same faded look as :disabled.

Tests

  • New tests in e2e/focus-qa3.spec.ts: Save, then Ctrl/⌘+Z undoes in a document, a sheet and slides, and the Save button keeps a keyboard focus while it saves. All 4 fail without the fix and pass with it.
  • Four existing tests clicked back into the document after Save, with the comment "Save took the focus". The xlsx, pptx and Markdown math tests no longer click back, so they now cover the fix too. The docx track-changes test only had its comment fixed, because it still needs the caret moved.
  • Unit tests: 1765 pass. Typecheck is clean. The e2e files touched by this change pass locally on macOS, except two failures this change does not cause:
    • a long deck fails because the generated large-deck.pptx sample is not on this machine.
    • The Markdown math test uses Control+c to copy, which does not copy on macOS. A copy of it with ControlOrMeta+ passes.

🤖 Generated with Claude Code

…l/⌘+Z undoes there

The Save button took the focus on a click and was disabled while it saved. A disabled
button loses its focus to the page, out of the viewer, so Ctrl/⌘+Z and every other
shortcut did nothing until the document was clicked again. The Undo button still worked.

The button now keeps the focus where it was on mousedown, as the toolbar's buttons do,
and is aria-disabled while it saves, so a keyboard focus on it stays too. saveFile
already refuses a second save while one runs.

The e2e tests that clicked back into the document after Save no longer do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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