keyboard.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. // XXX This shortcut should also work when hovering over a card in board view
  63. Mousetrap.bind('c', evt => {
  64. if (!Session.get('currentCard')) {
  65. return;
  66. }
  67. const currentUserId = Meteor.userId();
  68. if (currentUserId === null) {
  69. return;
  70. }
  71. if (
  72. Meteor.user().isBoardMember() &&
  73. !Meteor.user().isCommentOnly() &&
  74. !Meteor.user().isWorker()
  75. ) {
  76. const card = Cards.findOne(Session.get('currentCard'));
  77. card.archive();
  78. // We should prevent scrolling in card when spacebar is clicked
  79. // This should do it according to Mousetrap docs, but it doesn't
  80. evt.preventDefault();
  81. }
  82. });
  83. Template.keyboardShortcuts.helpers({
  84. mapping: [
  85. {
  86. keys: ['W'],
  87. action: 'shortcut-toggle-sidebar',
  88. },
  89. {
  90. keys: ['Q'],
  91. action: 'shortcut-filter-my-cards',
  92. },
  93. {
  94. keys: ['F'],
  95. action: 'shortcut-toggle-filterbar',
  96. },
  97. {
  98. keys: ['X'],
  99. action: 'shortcut-clear-filters',
  100. },
  101. {
  102. keys: ['?'],
  103. action: 'shortcut-show-shortcuts',
  104. },
  105. {
  106. keys: ['ESC'],
  107. action: 'shortcut-close-dialog',
  108. },
  109. {
  110. keys: ['@'],
  111. action: 'shortcut-autocomplete-members',
  112. },
  113. {
  114. keys: ['SPACE'],
  115. action: 'shortcut-assign-self',
  116. },
  117. {
  118. keys: ['C'],
  119. action: 'archive-card',
  120. },
  121. ],
  122. });