Parcourir la source

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

Nadav Tasher il y a 5 mois
Parent
commit
fb008569ab
1 fichiers modifiés avec 16 ajouts et 0 suppressions
  1. 16 0
      client/lib/keyboard.js

+ 16 - 0
client/lib/keyboard.js

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