keyboard.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // XXX There is no reason to define these shortcuts globally, they should be
  2. // attached to a template (most of them will go in the `board` template).
  3. Mousetrap.bind('?', () => {
  4. FlowRouter.go('shortcuts');
  5. });
  6. Mousetrap.bind('w', () => {
  7. if (Sidebar.isOpen() && Sidebar.getView() === 'home') {
  8. Sidebar.toggle();
  9. } else {
  10. Sidebar.setView();
  11. }
  12. });
  13. Mousetrap.bind('q', () => {
  14. const currentBoardId = Session.get('currentBoard');
  15. const currentUserId = Meteor.userId();
  16. if (currentBoardId && currentUserId) {
  17. Filter.members.toggle(currentUserId);
  18. }
  19. });
  20. Mousetrap.bind('x', () => {
  21. if (Filter.isActive()) {
  22. Filter.reset();
  23. }
  24. });
  25. Mousetrap.bind('f', () => {
  26. if (Sidebar.isOpen() && Sidebar.getView() === 'filter') {
  27. Sidebar.toggle();
  28. } else {
  29. Sidebar.setView('filter');
  30. }
  31. });
  32. Mousetrap.bind(['down', 'up'], (evt, key) => {
  33. if (!Session.get('currentCard')) {
  34. return;
  35. }
  36. const nextFunc = key === 'down' ? 'next' : 'prev';
  37. const nextCard = $('.js-minicard.is-selected')
  38. [nextFunc]('.js-minicard')
  39. .get(0);
  40. if (nextCard) {
  41. const nextCardId = Blaze.getData(nextCard)._id;
  42. Utils.goCardId(nextCardId);
  43. }
  44. });
  45. // XXX This shortcut should also work when hovering over a card in board view
  46. Mousetrap.bind('space', evt => {
  47. if (!Session.get('currentCard')) {
  48. return;
  49. }
  50. const currentUserId = Meteor.userId();
  51. if (currentUserId === null) {
  52. return;
  53. }
  54. if (Meteor.user().isBoardMember()) {
  55. const card = Cards.findOne(Session.get('currentCard'));
  56. card.toggleMember(currentUserId);
  57. // We should prevent scrolling in card when spacebar is clicked
  58. // This should do it according to Mousetrap docs, but it doesn't
  59. evt.preventDefault();
  60. }
  61. });
  62. Template.keyboardShortcuts.helpers({
  63. mapping: [
  64. {
  65. keys: ['W'],
  66. action: 'shortcut-toggle-sidebar',
  67. },
  68. {
  69. keys: ['Q'],
  70. action: 'shortcut-filter-my-cards',
  71. },
  72. {
  73. keys: ['F'],
  74. action: 'shortcut-toggle-filterbar',
  75. },
  76. {
  77. keys: ['X'],
  78. action: 'shortcut-clear-filters',
  79. },
  80. {
  81. keys: ['?'],
  82. action: 'shortcut-show-shortcuts',
  83. },
  84. {
  85. keys: ['ESC'],
  86. action: 'shortcut-close-dialog',
  87. },
  88. {
  89. keys: ['@'],
  90. action: 'shortcut-autocomplete-members',
  91. },
  92. {
  93. keys: ['SPACE'],
  94. action: 'shortcut-assign-self',
  95. },
  96. ],
  97. });