diff --git a/ui/app/controllers/application.js b/ui/app/controllers/application.js index 4bb89427449..be1756c0ee8 100644 --- a/ui/app/controllers/application.js +++ b/ui/app/controllers/application.js @@ -25,7 +25,6 @@ export default class ApplicationController extends Controller { // eslint-disable-next-line ember/classic-decorator-hooks constructor() { super(...arguments); - console.log('do i listen for keypress'); this.keyboard.listenForKeypress(); } diff --git a/ui/app/helpers/keyboard-commands.js b/ui/app/helpers/keyboard-commands.js index f048ebb658b..f03fd4b92e7 100644 --- a/ui/app/helpers/keyboard-commands.js +++ b/ui/app/helpers/keyboard-commands.js @@ -10,12 +10,10 @@ export default class keyboardCommands extends Helper { @service keyboard; constructor() { - console.log('kc const', ...arguments); super(...arguments); } compute([commands]) { - console.log('computing', commands); if (commands) { this.commands = commands; this.keyboard.addCommands(commands); diff --git a/ui/app/modifiers/keyboard-shortcut.js b/ui/app/modifiers/keyboard-shortcut.js index 1704a487c3b..1ddcaaa6535 100644 --- a/ui/app/modifiers/keyboard-shortcut.js +++ b/ui/app/modifiers/keyboard-shortcut.js @@ -25,9 +25,9 @@ export default class KeyboardShortcutModifier extends Modifier { element, menuLevel, enumerated, - url: this.router.currentURL, }, ]; + this.keyboard.addCommands(commands); registerDestructor(this, () => { this.keyboard.removeCommands(commands); diff --git a/ui/app/services/keyboard.js b/ui/app/services/keyboard.js index 1edfb99cd8d..a35619bee5c 100644 --- a/ui/app/services/keyboard.js +++ b/ui/app/services/keyboard.js @@ -169,35 +169,28 @@ export default class KeyboardService extends Service { return [`Shift+${('0' + iter).slice(-2)}`]; // Shift+01, not Shift+1 } + recomputeEnumeratedCommands() { + this.keyCommands.filterBy('enumerated').forEach((command, iter) => { + command.pattern = this.cleanPattern(iter); + }); + } + addCommands(commands) { - commands.forEach((command) => { - if (command.enumerated) { - // Ember's registerDestructor on destroyables fires AFTER a page load, meaning our enumerated array will be full of both old and new commands. - // Filter not only by enumerated, but also make sure we're only counting by those commands with our new command's URL. - // Without this second filterBy, moving from tabled-page to tabled-page will start your new commands at a number greater than 01. - command.pattern = this.cleanPattern( - this.keyCommands - .filterBy('enumerated') - .filter((c) => c.url === command.url).length - ); - } + schedule('afterRender', () => { + commands.forEach((command) => { + this.keyCommands.pushObject(command); + if (command.enumerated) { + // Recompute enumerated numbers to handle things like sort + this.recomputeEnumeratedCommands(); + } + }); }); - this.keyCommands.pushObjects(commands); } removeCommands(commands = A([])) { this.keyCommands.removeObjects(commands); } - @action - generateIteratorShortcut(element, [action, iter]) { - this.keyCommands.pushObject({ - label: `Hit up item ${iter}`, - pattern: [`Shift+${iter}`], - action, - }); - } - //#region Nav Traversal subnavLinks = [];