feat(editor): Backspace and « + » on a vertex handle
This commit is contained in:
1 parent
c01c6f3145
commit
6df66f9bb9
5 files changed
+108
-10
No files matched your search
@@ -169,6 +169,51 @@ test.describe('editor zones on the drawing (U2 Task 5)', () => {
|
|||||||
await undoTo(page, () => shownPoints(page), stored)
|
await undoTo(page, () => shownPoints(page), stored)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('Thoraciques: Backspace and « + » on a vertex, each undone, the group named in full', async ({
|
||||||
|
page,
|
||||||
|
requests,
|
||||||
|
}) => {
|
||||||
|
const actor = await openThoracic(page)
|
||||||
|
requests.forbid(actor.account.email, actor.account.password)
|
||||||
|
await pickAnnotation(page, dict, THORACIC)
|
||||||
|
await scrollToTop(page)
|
||||||
|
// Point 5: the group and a vertex carry the annotation's full name.
|
||||||
|
await expect(
|
||||||
|
page.getByRole('group', {
|
||||||
|
name: 'Sommets de Vertèbres thoraciques',
|
||||||
|
exact: true,
|
||||||
|
}),
|
||||||
|
).toBeAttached()
|
||||||
|
const stored = await shownPoints(page)
|
||||||
|
const third = handle(page, 'Sommet 3 de Vertèbres thoraciques')
|
||||||
|
await expect(third).toBeAttached()
|
||||||
|
|
||||||
|
// Backspace removes the focused vertex, as Delete; undone.
|
||||||
|
await third.focus()
|
||||||
|
await page.keyboard.press('Backspace')
|
||||||
|
await expect(line(page)).toContainText(
|
||||||
|
dict['editor.annotations.message.vertex_removed'],
|
||||||
|
)
|
||||||
|
expect(await count(page)).toBe(stored.length - 1)
|
||||||
|
await undoTo(page, () => shownPoints(page), stored)
|
||||||
|
|
||||||
|
// « + » adds after the focused vertex, as Insert, the canvas zoom untouched; undone.
|
||||||
|
// The undo cleared the choice but left the focus: moving it chooses again.
|
||||||
|
await handle(page, 'Sommet 2 de Vertèbres thoraciques').focus()
|
||||||
|
await handle(page, 'Sommet 3 de Vertèbres thoraciques').focus()
|
||||||
|
const drawing = page.getByTestId('annotation-canvas-drawing').locator('..')
|
||||||
|
const framed = () =>
|
||||||
|
drawing.evaluate((el) => getComputedStyle(el).transform)
|
||||||
|
const zoomed = await framed()
|
||||||
|
await page.keyboard.press('+')
|
||||||
|
await expect(line(page)).toContainText(
|
||||||
|
dict['editor.annotations.message.vertex_added'],
|
||||||
|
)
|
||||||
|
expect(await count(page)).toBe(stored.length + 1)
|
||||||
|
expect(await framed()).toBe(zoomed)
|
||||||
|
await undoTo(page, () => count(page), stored.length)
|
||||||
|
})
|
||||||
|
|
||||||
test('Thoraciques: « Désélectionner » commits the arrow steps pending on a vertex', async ({
|
test('Thoraciques: « Désélectionner » commits the arrow steps pending on a vertex', async ({
|
||||||
page,
|
page,
|
||||||
requests,
|
requests,
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ function Vertex({
|
|||||||
tabIndex={0}
|
tabIndex={0}
|
||||||
aria-label={label}
|
aria-label={label}
|
||||||
aria-pressed={chosen}
|
aria-pressed={chosen}
|
||||||
|
aria-keyshortcuts="Insert Plus Delete Backspace"
|
||||||
data-vertex={index}
|
data-vertex={index}
|
||||||
// Its arrow series commits on blur; the drawing guard blurs it before leaving.
|
// Its arrow series commits on blur; the drawing guard blurs it before leaving.
|
||||||
data-series=""
|
data-series=""
|
||||||
|
|||||||
@@ -113,9 +113,28 @@ function deleteChosen(input: ZoneEditInput): void {
|
|||||||
chooseVertex(id, Math.min(chosen, left))
|
chooseVertex(id, Math.min(chosen, left))
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A vertex handle's keys (board 32): arrows step it, Enter commits, Insert adds, Delete. */
|
const INSERT_KEYS = ['Insert', '+']
|
||||||
function vertexKey(input: ZoneEditInput, index: number, event: KeyboardEvent) {
|
const REMOVE_KEYS = ['Delete', 'Backspace']
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Insert or « + » adds after the chosen vertex, Delete or Backspace removes it (Mac keyboards
|
||||||
|
* have no Insert and Delete is Backspace; « + » is the drawn « + », whatever the layout).
|
||||||
|
*/
|
||||||
|
function editKey(input: ZoneEditInput, event: KeyboardEvent): void {
|
||||||
|
event.preventDefault()
|
||||||
|
// Final review I-1: a move mode changes the position only, as the press machine does.
|
||||||
|
if (inMoveMode()) return
|
||||||
|
// I-1: arrow steps still pending are committed first; the change applies to that place.
|
||||||
|
commitKeys(input)
|
||||||
const id = input.target?.id
|
const id = input.target?.id
|
||||||
|
const chosen = id ? freshChosen(id) : null
|
||||||
|
if (INSERT_KEYS.includes(event.key) && chosen !== null)
|
||||||
|
insertAfter(input, chosen)
|
||||||
|
if (REMOVE_KEYS.includes(event.key)) deleteChosen(input)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A vertex handle's keys (board 32): arrows step it, Enter commits, the edit keys above. */
|
||||||
|
function vertexKey(input: ZoneEditInput, index: number, event: KeyboardEvent) {
|
||||||
if (STEP[event.key]) {
|
if (STEP[event.key]) {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
return stepVertex(input, index, event)
|
return stepVertex(input, index, event)
|
||||||
@@ -124,14 +143,8 @@ function vertexKey(input: ZoneEditInput, index: number, event: KeyboardEvent) {
|
|||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
return inMoveMode() ? input.confirmMove() : commitKeys(input)
|
return inMoveMode() ? input.confirmMove() : commitKeys(input)
|
||||||
}
|
}
|
||||||
if (event.key !== 'Insert' && event.key !== 'Delete') return
|
if (INSERT_KEYS.includes(event.key) || REMOVE_KEYS.includes(event.key))
|
||||||
// Final review I-1: a move mode changes the position only, as the press machine does.
|
editKey(input, event)
|
||||||
if (inMoveMode()) return
|
|
||||||
// I-1: arrow steps still pending are committed first; the change applies to that place.
|
|
||||||
commitKeys(input)
|
|
||||||
const chosen = id ? freshChosen(id) : null
|
|
||||||
if (event.key === 'Insert' && chosen !== null) insertAfter(input, chosen)
|
|
||||||
if (event.key === 'Delete') deleteChosen(input)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Enter or Space on a « + » or on the « − » bubble is its click. */
|
/** Enter or Space on a « + » or on the « − » bubble is its click. */
|
||||||
|
|||||||
@@ -352,6 +352,21 @@ describe('« Reprendre le tracé » edits the closed shape with its handles (boa
|
|||||||
expect(untouched()).toEqual(before)
|
expect(untouched()).toEqual(before)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('Backspace and « + » on a pending vertex act as Delete and Insert, nothing held', async () => {
|
||||||
|
await resumed()
|
||||||
|
const before = untouched()
|
||||||
|
const vertex = (n: number) =>
|
||||||
|
screen.getByRole('button', { name: `Sommet ${n} de Tibia` })
|
||||||
|
vertex(1).focus()
|
||||||
|
expect(fireEvent.keyDown(vertex(1), { key: '+' })).toBe(false)
|
||||||
|
expect(shape()).toHaveLength(5)
|
||||||
|
expect(shape()![1]).toEqual([50, 20])
|
||||||
|
expect(useAnnotationWork.getState().chosen).toMatchObject({ vertex: 1 })
|
||||||
|
expect(fireEvent.keyDown(vertex(2), { key: 'Backspace' })).toBe(false)
|
||||||
|
expect(shape()).toEqual(SQUARE)
|
||||||
|
expect(untouched()).toEqual(before)
|
||||||
|
})
|
||||||
|
|
||||||
it('« − » at three vertices is refused with its reason', async () => {
|
it('« − » at three vertices is refused with its reason', async () => {
|
||||||
await resumed('Tibia', SQUARE.slice(0, 3))
|
await resumed('Tibia', SQUARE.slice(0, 3))
|
||||||
clickHandle('Sommet 1 de Tibia', [20, 20])
|
clickHandle('Sommet 1 de Tibia', [20, 20])
|
||||||
|
|||||||
@@ -241,6 +241,30 @@ describe('a vertex (R-9)', () => {
|
|||||||
expect(message()).toHaveTextContent('Sommet retiré')
|
expect(message()).toHaveTextContent('Sommet retiré')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('Backspace removes and « + » inserts like Delete and Insert, one commit each, the default prevented', async () => {
|
||||||
|
await mount(squareText())
|
||||||
|
await select()
|
||||||
|
const before = depth()
|
||||||
|
vertex(1).focus()
|
||||||
|
expect(fireEvent.keyDown(vertex(1), { key: '+' })).toBe(false)
|
||||||
|
expect(pointsOf('z')).toHaveLength(5)
|
||||||
|
expect(chosen()).toMatchObject({ vertex: 1 })
|
||||||
|
expect(fireEvent.keyDown(vertex(2), { key: 'Backspace' })).toBe(false)
|
||||||
|
expect(pointsOf('z')).toEqual(SQUARE)
|
||||||
|
expect(depth()).toBe(before + 2)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Backspace at three vertices keeps them with the reason; « + » needs no drawn « + »', async () => {
|
||||||
|
await mount(squareText(SQUARE.slice(0, 3)))
|
||||||
|
await select()
|
||||||
|
vertex(1).focus()
|
||||||
|
fireEvent.keyDown(vertex(1), { key: 'Backspace' })
|
||||||
|
expect(pointsOf('z')).toHaveLength(3)
|
||||||
|
expect(message()).toHaveTextContent('Une zone garde au moins 3 sommets')
|
||||||
|
fireEvent.keyDown(vertex(1), { key: '+' })
|
||||||
|
expect(pointsOf('z')).toHaveLength(4)
|
||||||
|
})
|
||||||
|
|
||||||
it('« − » is disabled at 3 with its reason; nothing is removed', async () => {
|
it('« − » is disabled at 3 with its reason; nothing is removed', async () => {
|
||||||
const triangle = SQUARE.slice(0, 3)
|
const triangle = SQUARE.slice(0, 3)
|
||||||
await mount(squareText(triangle))
|
await mount(squareText(triangle))
|
||||||
|
|||||||
Reference in new issue
Block a user