Fix issue #84: Double click token
All checks were successful
Test / test (push) Successful in 2s

This commit is contained in:
Gitea OpenCode Agent
2026-10-15 20:44:53 +00:00
parent 2c1cc970e6
commit 5ee7353123
3 changed files with 25 additions and 3 deletions

View File

@@ -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)"
>

View File

@@ -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.

View File

@@ -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['"]/);