From 75b8fdc3aa238f34825cd08faa6906e9b818f47c Mon Sep 17 00:00:00 2001 From: Florrie Date: Sun, 3 May 2020 14:49:40 -0300 Subject: clean up some context menu logic to fix reveal bug --- todo.txt | 5 ++--- ui.js | 13 ++++++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/todo.txt b/todo.txt index bd75904..c99c70d 100644 --- a/todo.txt +++ b/todo.txt @@ -4,10 +4,8 @@ TODO: A way to see the path of the currently selected item in any grouplike (Done!) TODO: A "shuffle queue" button! - (Half-way done -- the functionality is there, press "S", but there's no - button for it yet.) - TODO: A "clear queue" button. + (Done! Press S or C, or choose the option from the menubar.) TODO: A way to jump to an item with a particular name. Probably press "/". It'd be nice if the closest match got highlighted while you were typing. @@ -509,3 +507,4 @@ TODO: Revisit labels and notes features! They're commented out for now :P TODO: Pressing "Reveal" should focus the main listing. This is prrrrobably a case of context menu selection-restoring being a pain. + (Done!) diff --git a/ui.js b/ui.js index 5c586dd..0172fc2 100644 --- a/ui.js +++ b/ui.js @@ -3751,6 +3751,7 @@ class ContextMenu extends FocusElement { button.keyboardIdentifier = item.keyboardIdentifier || item.label if (item.action) { button.on('pressed', async () => { + this.restoreSelection() if (await item.action() === 'reload') { this.reload() } else { @@ -3797,6 +3798,7 @@ class ContextMenu extends FocusElement { keyPressed(keyBuf) { if (telc.isEscape(keyBuf) || telc.isBackspace(keyBuf)) { + this.restoreSelection() this.close() return false } else if (this.keyboardSelector.keyPressed(keyBuf)) { @@ -3819,24 +3821,25 @@ class ContextMenu extends FocusElement { } if (this.visible) { - const newlySelected = this.root.selectedElement this.close() - newlySelected.root.select(newlySelected) } } close(remove = true) { this.clearItems() this.visible = false - if (this.selectedBefore.root.select) { - this.selectedBefore.root.select(this.selectedBefore) - } if (remove && this.parent) { this.parent.removeChild(this) this.emit('closed') } } + restoreSelection() { + if (this.selectedBefore.root.select) { + this.selectedBefore.root.select(this.selectedBefore) + } + } + clearItems() { // Abhorrent hack - just erases children from memory. Leaves children // thinking they've still got a parent, though. (Necessary to avoid crazy -- cgit 1.3.0-6-gf8a5