Files
wekan/client/lib/dueDateHotkey.js
T
Lauri Ojansivu 8508c15015 Keyboard shortcuts Shift+M for Move Card and Shift+C for Copy Card.
They act on the opened card, or on the hovered or selected minicard,
which is opened first, as the d due date shortcut does. Like d, they do
not open the popup themselves: client/lib/cardMenuHotkey.js clicks the
opened card's hamburger menu and then its Move Card or Copy Card item,
so the menu's permissions decide - Move Card for board admins, Copy
Card for everyone who is not a Worker. A menu without the item is
closed again. Shift keeps them apart from m (assign yourself) and c
(archive). The keyboard shortcuts list names them with the already
translated popup titles, and docs/Features/General/Keyboard-Shortcuts
lists the opened card's shortcuts.

findOpenedCardDetails() is shared from client/lib/dueDateHotkey.js.

tests/cardMenuKeyboardShortcut.test.cjs drives the DOM logic, including
a menu without the item, another opened card and a stray element, and
tests/playwright/specs/move-copy-keyboard-shortcut-6904.e2e.js presses
the keys, with shortcuts off, while typing, and as a non-admin member.

User-defined shortcuts, the question in the issue, are not part of this.

Thanks to mimZD and xet7 !

Fixes #6904.
2026-11-14 18:36:51 +02:00

55 lines
2.6 KiB
JavaScript

// #6750: the `d` keyboard shortcut opens the Due date editor of the opened
// card. It does not open the popup itself: it finds the control the card
// details already render for the due date - the `+` (`.js-due-date`) when the
// card has no due date, the date badge (`.js-edit-date`) when it has one - and
// the caller clicks it. So the shortcut can never do more than a click could:
// the card details render those controls only when the board allows due dates,
// the user may modify the card (canModifyCard) and, for the `+`, is not a
// Worker. With no such control there is nothing to click, and nothing happens.
//
// Pure DOM logic, no Meteor imports, so tests/dueDateKeyboardShortcut.test.cjs
// can drive it without a browser.
export const DUE_DATE_CONTROL_SELECTOR =
'.card-details-item-due .js-edit-date, .card-details-item-due .js-due-date';
// root: a document or element holding the card details.
// cardId: the opened card (Utils.getCurrentCardId()); nothing without one.
// canModifyCard: Utils.canModifyCard(card) - checked again here so a stale
// control left in the DOM cannot be used by somebody who may not edit.
// dataOf: returns the data context of a `.js-card-details` element
// (Blaze.getData in the client), so the control of the OPENED card is chosen
// when more than one card details is on the page.
function dataCardId(data) {
if (!data) return null;
if (typeof data._id === 'string') return data._id;
if (data.card && typeof data.card._id === 'string') return data.card._id;
return null;
}
// The `.js-card-details` of the OPENED card. A details element whose card
// cannot be read is used only when it is the ONLY card details on the page -
// then it is the opened card - never when another card's details could be
// meant. Shared with the Move / Copy shortcuts (client/lib/cardMenuHotkey.js).
export function findOpenedCardDetails(root, { cardId, dataOf } = {}) {
if (!root || !cardId) return null;
const details = Array.from(root.querySelectorAll('.js-card-details'));
const known = details.map(element => {
try {
return dataCardId(dataOf ? dataOf(element) : null);
} catch (e) {
return null;
}
});
let target = details.find((element, i) => known[i] === cardId);
if (!target && details.length === 1 && known[0] === null) target = details[0];
return target || null;
}
export function findDueDateControl(root, { cardId, canModifyCard, dataOf } = {}) {
if (!root || !cardId || !canModifyCard) return null;
const target = findOpenedCardDetails(root, { cardId, dataOf });
if (!target) return null;
return target.querySelector(DUE_DATE_CONTROL_SELECTOR) || null;
}