Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion e2e/docx-track.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
65 changes: 65 additions & 0 deletions e2e/focus-qa3.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([])
})
})
3 changes: 1 addition & 2 deletions e2e/markdown-math.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 1 addition & 5 deletions e2e/pptx.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions e2e/xlsx.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(/<c r="M\d+"/g) ?? []).length).toBeLessThan(10)

// Undo takes the formats back, one at a time (the Save button has the focus: back to the grid)
await v.clickCell('J10')
// Undo takes the formats back, one at a time (Save left the focus in the grid)
await v.page.keyboard.press('Control+z')
await v.page.waitForTimeout(300)
expect((await cellBox(v, 'K22'))?.style ?? '').not.toMatch(yellow)
Expand Down
12 changes: 11 additions & 1 deletion src/react/DocViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,17 @@ function Viewer(props: DocViewerProps) {
</button>
)}
{client && canSave && ((editing && !readOnly) || dirty) && (
<button type="button" className={dirty ? 'de-mode de-save-dirty' : 'de-mode'} disabled={saving} onClick={() => void save()} title={t.bar.saveTitle}>
// a click leaves the focus in the document (as the toolbar's buttons do), so Ctrl/⌘+Z goes on undoing there;
// aria-disabled, not disabled, while it saves: a disabled button loses the focus to the page, out of the viewer
// (a second save is refused by saveFile itself)
<button
type="button"
className={dirty ? 'de-mode de-save-dirty' : 'de-mode'}
aria-disabled={saving}
onMouseDown={(e) => e.preventDefault()}
onClick={() => void save()}
title={t.bar.saveTitle}
>
<Icon name="save" size={16} />
{saving ? t.bar.saving : dirty || onSave ? t.bar.save : t.bar.download}
</button>
Expand Down
2 changes: 1 addition & 1 deletion src/react/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down