Skip to content

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

Merged
pierreneter merged 3 commits into
mainfrom
fix/save-keeps-focus
Dec 4, 2026
Merged

pierreneter merged 3 commits into
mainfrom
fix/save-keeps-focus

Conversation

@pierreneter

@pierreneter pierreneter commented Dec 4, 2026 •

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.

A click on Save used to blur a cell still being typed in, and that blur wrote the cell. Now the focus stays, so src/react/xlsx/XlsxView.tsx gives the sheet a flush: before a save, or an export from the File menu, it writes the cell being typed in (in the cell or the formula bar), as Enter would, and waits for the edits sent. Without it the file was saved without the text.

Other fields write as they lose the focus too: a sheet's name being typed, a font size typed in the toolbar, the word an IME is still composing (Telex half way through a word). So the click on Save now blurs the field that has the focus, as when the button took it, and then gives the focus back to it, unless its blur put it elsewhere (a cell gives it to its grid) or the field went away with its edit (a sheet's name). Without it, each of these was saved without what was typed.

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.
  • A fifth test in e2e/focus-qa3.spec.ts: text typed in a cell, then in the formula bar, with no Enter before Save, is in the saved file, and Ctrl/⌘+Z then takes the cell back. It fails without the sheet's flush (the cell is saved empty).
  • Three more tests there: a word an IME is composing (Input.imeSetComposition) is in the saved document and the typing goes on after it; a font size typed with no Enter is in the saved document; a sheet's name still being typed is the one saved. All 3 fail without the blur.
  • 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

pierreneter and others added 3 commits December 4, 2026 11:44
…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>
Since the Save button keeps the focus in the document, a click on it no
longer blurs the cell being typed in, and the blur was what wrote it: the
file was saved without the text. The sheet's flush now writes that cell,
as Enter would, and waits for the edits sent, before a save or an export
from the File menu.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ds, then gives the focus back

Since a click on Save keeps the focus where it is, a field that writes as it
loses the focus was not written before the save: a sheet's name being typed,
a font size typed in the toolbar, the word an IME is still composing. The
button now blurs that field first, as when it took the focus, then gives the
focus back to it, unless its blur put it elsewhere or it went away with its
edit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pierreneter
pierreneter merged commit 9340163 into main Dec 4, 2026
2 checks passed
@pierreneter
pierreneter deleted the fix/save-keeps-focus branch December 4, 2026 23:20
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