Make sure keyboard shortcuts are enabled and no text is selected on shortcut triggers

This commit is contained in:
Nadav Tasher 2024-12-25 00:24:41 +02:00
parent 295c9c8617
commit fb008569ab

View file

@ -14,6 +14,22 @@ window.addEventListener('keydown', (e) => {
Mousetrap.trigger(String.fromCharCode(e.which).toLowerCase());
});
// Store the original stopCallback in a global
const originalStopCallback = Mousetrap.stopCallback;
// Overwrite the stopCallback to allow for more keyboard shortcut customizations
Mousetrap.stopCallback = (e, element) => {
// Are shortcuts enabled for the user?
if (!ReactiveCache.getCurrentUser().isKeyboardShortcuts())
return true;
// Make sure there are no selected characters
if (window.getSelection().type === "Range")
return true;
return originalStopCallback(e, element);
}
function getHoveredCardId() {
const card = $('.js-minicard:hover').get(0);
if (!card) return null;