Browse Source

Merge pull request #3066 from marc1006/shortcuts

Fix shortcuts list and support card shortcuts when hovering a card
Lauri Ojansivu 5 years ago
parent
commit
e42adcaed0
1 changed files with 21 additions and 11 deletions
  1. 21 11
      client/lib/keyboard.js

+ 21 - 11
client/lib/keyboard.js

@@ -1,6 +1,16 @@
 // XXX There is no reason to define these shortcuts globally, they should be
 // XXX There is no reason to define these shortcuts globally, they should be
 // attached to a template (most of them will go in the `board` template).
 // attached to a template (most of them will go in the `board` template).
 
 
+function getHoveredCardId() {
+  const card = $('.js-minicard:hover').get(0);
+  if (!card) return null;
+  return Blaze.getData(card)._id;
+}
+
+function getSelectedCardId() {
+  return Session.get('selectedCard') || getHoveredCardId();
+}
+
 Mousetrap.bind('?', () => {
 Mousetrap.bind('?', () => {
   FlowRouter.go('shortcuts');
   FlowRouter.go('shortcuts');
 });
 });
@@ -50,9 +60,9 @@ Mousetrap.bind(['down', 'up'], (evt, key) => {
   }
   }
 });
 });
 
 
-// XXX This shortcut should also work when hovering over a card in board view
 Mousetrap.bind('space', evt => {
 Mousetrap.bind('space', evt => {
-  if (!Session.get('currentCard')) {
+  const cardId = getSelectedCardId();
+  if (!cardId) {
     return;
     return;
   }
   }
 
 
@@ -62,7 +72,7 @@ Mousetrap.bind('space', evt => {
   }
   }
 
 
   if (Meteor.user().isBoardMember()) {
   if (Meteor.user().isBoardMember()) {
-    const card = Cards.findOne(Session.get('currentCard'));
+    const card = Cards.findOne(cardId);
     card.toggleMember(currentUserId);
     card.toggleMember(currentUserId);
     // We should prevent scrolling in card when spacebar is clicked
     // We should prevent scrolling in card when spacebar is clicked
     // This should do it according to Mousetrap docs, but it doesn't
     // This should do it according to Mousetrap docs, but it doesn't
@@ -70,9 +80,9 @@ Mousetrap.bind('space', evt => {
   }
   }
 });
 });
 
 
-// XXX This shortcut should also work when hovering over a card in board view
 Mousetrap.bind('c', evt => {
 Mousetrap.bind('c', evt => {
-  if (!Session.get('currentCard')) {
+  const cardId = getSelectedCardId();
+  if (!cardId) {
     return;
     return;
   }
   }
 
 
@@ -86,7 +96,7 @@ Mousetrap.bind('c', evt => {
     !Meteor.user().isCommentOnly() &&
     !Meteor.user().isCommentOnly() &&
     !Meteor.user().isWorker()
     !Meteor.user().isWorker()
   ) {
   ) {
-    const card = Cards.findOne(Session.get('currentCard'));
+    const card = Cards.findOne(cardId);
     card.archive();
     card.archive();
     // We should prevent scrolling in card when spacebar is clicked
     // We should prevent scrolling in card when spacebar is clicked
     // This should do it according to Mousetrap docs, but it doesn't
     // This should do it according to Mousetrap docs, but it doesn't
@@ -97,19 +107,19 @@ Mousetrap.bind('c', evt => {
 Template.keyboardShortcuts.helpers({
 Template.keyboardShortcuts.helpers({
   mapping: [
   mapping: [
     {
     {
-      keys: ['W'],
+      keys: ['w'],
       action: 'shortcut-toggle-sidebar',
       action: 'shortcut-toggle-sidebar',
     },
     },
     {
     {
-      keys: ['Q'],
+      keys: ['q'],
       action: 'shortcut-filter-my-cards',
       action: 'shortcut-filter-my-cards',
     },
     },
     {
     {
-      keys: ['F'],
+      keys: ['f'],
       action: 'shortcut-toggle-filterbar',
       action: 'shortcut-toggle-filterbar',
     },
     },
     {
     {
-      keys: ['X'],
+      keys: ['x'],
       action: 'shortcut-clear-filters',
       action: 'shortcut-clear-filters',
     },
     },
     {
     {
@@ -129,7 +139,7 @@ Template.keyboardShortcuts.helpers({
       action: 'shortcut-assign-self',
       action: 'shortcut-assign-self',
     },
     },
     {
     {
-      keys: ['C'],
+      keys: ['c'],
       action: 'archive-card',
       action: 'archive-card',
     },
     },
   ],
   ],