diff --git a/frontend/app/components/viewer/map/MapViewerPane.vue b/frontend/app/components/viewer/map/MapViewerPane.vue index 65faf0de..6f9ed1e8 100644 --- a/frontend/app/components/viewer/map/MapViewerPane.vue +++ b/frontend/app/components/viewer/map/MapViewerPane.vue @@ -436,6 +436,14 @@ async function onTokenPointerUp(event) { await placeToken(token.actor, { x, y }); } +// Double clicking a token (or Enter on a focused one) opens the sheet of the actor it stands for. +// A single click cannot be the trigger: the click that ends a drag lands on the token too, so +// dragging a token over the map would open its sheet every time. +function openTokenSheet(token) { + const actor = tokenActor(token); + if (actor) openActorSheet(actor); +} + const CELL_STEPS = { ArrowLeft: [-1, 0], ArrowRight: [1, 0], @@ -443,7 +451,8 @@ const CELL_STEPS = { ArrowDown: [0, 1] }; -// A focused token answers to the keyboard too: arrows walk it over the grid, Delete takes it off. +// A focused token answers to the keyboard too: arrows walk it over the grid, Delete takes it off +// and Enter opens its sheet, the way a double click does. async function onTokenKeydown(event, token) { const step = CELL_STEPS[event.key]; if (step) { @@ -456,6 +465,7 @@ async function onTokenKeydown(event, token) { event.preventDefault(); await removeToken(token); } + if (event.key === 'Enter') openTokenSheet(token); } function onTokenContextMenu(token) { @@ -609,6 +619,7 @@ onBeforeUnmount(() => { @pointermove="onTokenPointerMove" @pointerup="onTokenPointerUp" @pointercancel="onTokenPointerUp" + @dblclick="openTokenSheet(token)" @contextmenu.stop.prevent="onTokenContextMenu(token)" @keydown="onTokenKeydown($event, token)" > diff --git a/frontend/app/content/docs/02-using-dragonroll/03-maps.md b/frontend/app/content/docs/02-using-dragonroll/03-maps.md index 0ad244c3..6df973f0 100644 --- a/frontend/app/content/docs/02-using-dragonroll/03-maps.md +++ b/frontend/app/content/docs/02-using-dragonroll/03-maps.md @@ -44,8 +44,8 @@ cell you dropped it on and is sized by that cell, so a huge creature can be give sizing it up on the map's settings. Once a token is on the map you can drag it to another cell, step it across the grid one cell at a time -with the **arrow keys**, and take it off with **Delete**. Clicking a token opens the sheet of the actor -it stands for. +with the **arrow keys**, and take it off with **Delete**. Double-clicking a token opens the sheet of +the actor it stands for, and **Enter** does the same on a token focused with the keyboard. Tokens belong to the map, not to the actor: the same character can stand on several maps, and taking a token off does not remove the character from the campaign. diff --git a/tests/map-tokens.test.js b/tests/map-tokens.test.js index 96f4ff9a..beed2269 100644 --- a/tests/map-tokens.test.js +++ b/tests/map-tokens.test.js @@ -341,6 +341,17 @@ function mapViewerTokenWiringTests() { assert.match(pane, /@contextmenu\.stop\.prevent="onTokenContextMenu\(token\)"/); }); + test("double clicking a token opens its actor's character sheet", () => { + assert.match(pane, /@dblclick="openTokenSheet\(token\)"/); + // The sheet is opened for the actor behind the token, and only when that actor is known. + assert.match(pane, /function openTokenSheet\(token\) \{[^}]*tokenActor\(token\)[^}]*openActorSheet\(/); + // A single click is not the trigger: it lands on the token at the end of every drag, so + // moving a token would open its sheet every time. + assert.doesNotMatch(pane, /@click="openTokenSheet\(/); + // The keyboard reaches the same sheet: Enter on a focused token, like its arrow keys. + assert.match(pane, /if \(event\.key === 'Enter'\) openTokenSheet\(token\);/); + }); + test("tokens are saved and taken off through the map routes", () => { assert.match(pane, /['"]\/map\/place-token['"]/); assert.match(pane, /['"]\/map\/remove-token['"]/);