From fcb9f2465dd2c87e55f98c105dd1beca45fbab2c Mon Sep 17 00:00:00 2001 From: Lptenoss Date: Fri, 4 Dec 2026 11:44:45 +0700 Subject: [PATCH] =?UTF-8?q?fix(viewer):=20a=20click=20on=20Save=20leaves?= =?UTF-8?q?=20the=20focus=20in=20the=20document,=20so=20Ctrl/=E2=8C=98+Z?= =?UTF-8?q?=20undoes=20there?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- e2e/docx-track.spec.ts | 2 +- e2e/focus-qa3.spec.ts | 65 +++++++++++++++++++++++++++++++++++++++ e2e/markdown-math.spec.ts | 3 +- e2e/pptx.spec.ts | 6 +--- e2e/xlsx.spec.ts | 3 +- src/react/DocViewer.tsx | 12 +++++++- src/react/styles.css | 2 +- 7 files changed, 81 insertions(+), 12 deletions(-) diff --git a/e2e/docx-track.spec.ts b/e2e/docx-track.spec.ts index 7d3788b..8c46d1a 100644 --- a/e2e/docx-track.spec.ts +++ b/e2e/docx-track.spec.ts @@ -62,7 +62,7 @@ describe('docx tracked changes', () => { await v.page.waitForTimeout(250) let ps = await docxParas((await v.save()).bytes) expect(show(ps.find((p) => show(p).startsWith('Hire'))!)).toBe('Hire the platform tea[-m]') - // typing at the caret (Save took the focus: put it back after "tea") goes in as inserted text, before the deletion + // typing at the caret, after "tea", goes in as inserted text, before the deletion await v.selectText('platform tea', 'end') await v.page.keyboard.type('ms') await v.page.waitForTimeout(250) diff --git a/e2e/focus-qa3.spec.ts b/e2e/focus-qa3.spec.ts index 972f31b..b67c596 100644 --- a/e2e/focus-qa3.spec.ts +++ b/e2e/focus-qa3.spec.ts @@ -86,3 +86,68 @@ describe('QA 3: spreadsheets', () => { expect(v.errors).toEqual([]) }) }) + +describe('a click on Save leaves the keyboard in the document', () => { + test('a document: the caret stays, Ctrl/⌘+Z undoes the typing just saved', async () => { + const v = await viewer({ src: 'samples/sample.docx', editable: true, onSave: true }) + await v.page.locator('.de-ebar').waitFor() + await v.selectText('Quarterly Report', 'end') + await v.page.keyboard.type('XYZ') + await v.page.waitForTimeout(200) + await v.save() + expect((await active(v)).cls).toContain('de-pages') + await v.page.keyboard.press('ControlOrMeta+z') + await v.page.waitForTimeout(200) + expect(await v.pagesText()).not.toContain('Quarterly ReportXYZ') + expect(v.errors).toEqual([]) + }) + + test('a sheet: the grid keeps the focus, Ctrl/⌘+Z takes the cell back', async () => { + const v = await viewer({ src: 'samples/sample.xlsx', editable: true, onSave: true }) + await v.page.locator('.de-ebar').waitFor() + await v.typeCell('J10', 'saved') + await v.save() + expect((await active(v)).inViewer).toBe(true) + await v.page.keyboard.press('ControlOrMeta+z') + await v.page.waitForTimeout(300) + expect(await v.shown('J10')).toBe('') + expect(v.errors).toEqual([]) + }) + + test('slides: Ctrl/⌘+Z takes back the text typed in a shape', async () => { + const v = await viewer({ src: 'samples/sample.pptx', editable: true, onSave: true }) + await v.page.locator('.de-ebar').waitFor() + const slide = v.page.locator('.de-slide-frame').first() + await slide.getByText('office-engine').first().click() + await v.page.locator('.de-txt-edit').waitFor() + await v.page.keyboard.press('ControlOrMeta+a') + await v.page.keyboard.type('Saved title') + await v.page.keyboard.press('Escape') + await v.page.keyboard.press('Escape') + await v.page.waitForTimeout(300) + await v.save() + expect((await active(v)).cls).toContain('de-scroll') + await v.page.keyboard.press('ControlOrMeta+z') + await v.page.waitForFunction(() => !document.querySelector('.de-slide-frame')?.textContent?.includes('Saved title')) + expect(await slide.innerText()).toContain('office-engine') + expect(v.errors).toEqual([]) + }) + + test('saving: the button is shown as busy but keeps a keyboard focus it had', async () => { + const v = await viewer({ src: 'samples/sample.docx', editable: true, onSave: true }) + await v.page.locator('.de-ebar').waitFor() + await v.selectText('Quarterly Report', 'end') + await v.page.keyboard.type('!') + await v.page.waitForTimeout(200) + const button = v.barButton('Save') + await button.focus() + const n = await saves(v) + await v.page.keyboard.press('Enter') + await v.waitEvent('save', n + 1) + await v.page.waitForTimeout(100) + const a = await active(v) + expect(a.tag).toBe('BUTTON') + expect(a.inViewer).toBe(true) + expect(v.errors).toEqual([]) + }) +}) diff --git a/e2e/markdown-math.spec.ts b/e2e/markdown-math.spec.ts index a62afa2..46d567d 100644 --- a/e2e/markdown-math.spec.ts +++ b/e2e/markdown-math.spec.ts @@ -124,8 +124,7 @@ describe('Markdown math in the document', () => { // (the paragraph is written again: its dollar signs are escaped only where they would be read as math) expect(saved).toContain('Euler’s identity: $e^{i\\pi} + 1 = 0$It costs $5 and $10, see `$x$`.') expect(saved).toContain('Euler’s identity: $e^{i\\pi} + 1 = 0$ is famous.') - // (Save took the focus) - await v.selectText('It costs', 'start') + // (Save left the focus in the document) await page.keyboard.press('Control+z') await page.waitForTimeout(300) expect(await inline()).toBe(3) diff --git a/e2e/pptx.spec.ts b/e2e/pptx.spec.ts index 04b45c9..2aecd97 100644 --- a/e2e/pptx.spec.ts +++ b/e2e/pptx.spec.ts @@ -77,11 +77,7 @@ describe('pptx editing', () => { expect(s1.meta.count).toBe(5) expect((await s1.slide(0)).els.some((e: any) => e.geom === 'rect' && e.fill?.c === '#00ff00')).toBe(true) - // Save took the focus: select the shape again (it is the topmost at the slide center) - const f = (await slide1(v).boundingBox())! - await v.page.mouse.click(f.x + f.width / 2, f.y + f.height / 2) - // a click on a shape with a text body edits its text: Esc keeps the shape selected - if (await v.page.locator('.de-txt-edit').count()) await stopEditing(v) + // Save left the shape selected await v.btn('Delete').waitFor() await v.btn('Delete').click() await v.page.waitForTimeout(300) diff --git a/e2e/xlsx.spec.ts b/e2e/xlsx.spec.ts index 875eceb..3cf37aa 100644 --- a/e2e/xlsx.spec.ts +++ b/e2e/xlsx.spec.ts @@ -1087,8 +1087,7 @@ describe('xlsx whole columns and rows (QA 19/11/2026, P2-042)', () => { // the column holds what was typed and where the row crosses it, not a cell per row expect((xml.match(/ )} {client && canSave && ((editing && !readOnly) || dirty) && ( - diff --git a/src/react/styles.css b/src/react/styles.css index c774f62..997c28a 100644 --- a/src/react/styles.css +++ b/src/react/styles.css @@ -705,7 +705,7 @@ .de-mode-on { border-color: var(--de-accent); color: var(--de-accent); } .de-save-dirty { background: var(--de-accent); border-color: var(--de-accent); color: var(--de-accent-ink); } .de-save-dirty:hover { background: var(--de-accent-hover); } -.de-mode:disabled { opacity: 0.6; cursor: default; } +.de-mode:disabled, .de-mode[aria-disabled='true'] { opacity: 0.6; cursor: default; } .de-ebar-host { flex: none; padding: 6px 10px;