浏览代码

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

Nadav Tasher 5 月之前
父节点
当前提交
fb008569ab
共有 1 个文件被更改,包括 16 次插入0 次删除
  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());
   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() {
 function getHoveredCardId() {
   const card = $('.js-minicard:hover').get(0);
   const card = $('.js-minicard:hover').get(0);
   if (!card) return null;
   if (!card) return null;