fix(editor): an unstarted frame ends silently on Escape and leave

This commit is contained in:
bchanot committed 2026-11-23 13:30:45 +01:00
1 parent 5736fe148d
commit 876960ccc7
4 files changed
+60 -5

No files matched your search

@@ -44,8 +44,8 @@ function asField(element: Element | EventTarget | null): HTMLElement | null {
}
/**
* A12: both are inactive during a creation or an open frame (R-13); I-1: redo also while work it would drop
* is pending (a started mode, a keyboard series, a slider change).
* A12: both are inactive during a creation or an open frame (R-13); I-1: redo also while
* work it would drop is pending (a started mode, a keyboard series, a slider change).
*/
const inactive = (
direction: Direction,
@@ -46,7 +46,7 @@ function endModeOnly(): void {
/**
* The drawing guard (R-12), asked by every navigation that would drop the drawing's work:
* a tab, a section, « Aller à », a view chip, a tool, Back, leaving the editor. Nothing
* started: an unstarted mode ends at once and the caller goes on (true). Work started:
* started: an unstarted mode or frame ends at once and the caller goes on (true). Work started:
* the question is shown (`DrawingGuardDialog`) and `proceed` waits for « Abandonner »
* (false).
*/
@@ -56,6 +56,8 @@ export function guardDrawing(proceed: () => void): boolean {
if (work === null) {
commitFocusedSeries()
endModeOnly()
// Like an unstarted mode, a frame with nothing drawn or changed loses nothing.
useAnnotationWork.setState({ frame: null })
return true
}
// A question already open keeps its own move (a Back over it is not replayed).
+3 -1
View File
@@ -130,7 +130,9 @@ export const useAnnotationWork = create<Work>(() => NO_WORK)
export type HistoryHold = 'creation' | 'creation_redo' | 'frame' | 'pending'
const sameBox = (a: Frame | null, b: Frame | null) =>
JSON.stringify(a) === JSON.stringify(b)
a === null || b === null
? a === b
: a.x === b.x && a.y === b.y && a.w === b.w && a.h === b.h
/** A frame asks only once a box is drawn (create) or differs from its start (recrop). */
const frameChanged = (frame: FrameWork | null) =>
+52 -1
View File
@@ -15,7 +15,7 @@ import ModalDialog from '@/components/ui/ModalDialog'
import DrawingGuardDialog from '@/components/editor/annotations/DrawingGuardDialog'
import { guardDrawing } from '@/editor/annotations/drawingGuard'
import { setFrameBox, startFrame } from '@/editor/annotations/frameWork'
import { resetWork } from '@/editor/annotations/workStore'
import { resetWork, useAnnotationWork } from '@/editor/annotations/workStore'
import { useLocaleStore } from '@/state/localeStore'
import { drawnText, edit, insert, point } from '../helpers/editorFixtures'
import { pressAt, resetStore, serverHas, store } from '../helpers/editorHarness'
@@ -416,3 +416,54 @@ describe('the frame guard dialog titles', () => {
expect(await screen.findByRole('dialog', { name: title })).toBeVisible()
})
})
describe('Escape over a frame', () => {
const open = () =>
act(() => {
startFrame({
purpose: 'create',
viewId: 'v',
drawnOn: 'v',
box: null,
returnTo: 'v',
})
})
afterEach(() => act(() => resetWork()))
it('an unstarted frame ends silently: no dialog, undo no longer held', async () => {
const user = await mount()
await select(user)
open()
expect(useAnnotationWork.getState().frame).not.toBeNull()
canvasBox().focus()
escape(canvasBox())
expect(useAnnotationWork.getState().frame).toBeNull()
expect(screen.queryByRole('dialog')).toBeNull()
expect(
screen.getByRole('button', { name: 'Défaire la dernière modification' }),
).not.toHaveAttribute('aria-describedby')
})
it('a started frame asks; « Abandonner » drops it', async () => {
const user = await mount()
await select(user)
open()
act(() => setFrameBox({ x: 1, y: 1, w: 9, h: 9 }))
canvasBox().focus()
escape(canvasBox())
const dialog = await screen.findByRole('dialog', {
name: 'Abandonner la création ?',
})
expect(useAnnotationWork.getState().frame).not.toBeNull()
await user.click(within(dialog).getByRole('button', { name: 'Abandonner' }))
expect(useAnnotationWork.getState().frame).toBeNull()
})
it('a navigation guard passes over an unstarted frame and clears it', () => {
open()
const proceed = vi.fn()
expect(guardDrawing(proceed)).toBe(true)
expect(useAnnotationWork.getState().frame).toBeNull()
expect(useAnnotationWork.getState().question).toBeNull()
})
})