From 376d169962e8080651b93adc9405901d8f601b4c Mon Sep 17 00:00:00 2001 From: Florrie Date: Tue, 17 Sep 2019 13:23:19 -0300 Subject: Fix select-el keys not working w/ context menus --- todo.txt | 3 +++ tui-lib | 2 +- ui.js | 12 ++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/todo.txt b/todo.txt index ef00c6d..c51c269 100644 --- a/todo.txt +++ b/todo.txt @@ -345,6 +345,7 @@ TODO: If you press any key which should select a particular element of the UI specific UI parts instead closes the context menu while one is open. We already have a key for doing just that (the cancel key, i.e. esc or period), so fix this! + (Done!) TODO: g/G should work for navigation in context menus! And probably all ListScrollForms, tbh, but I'm kinda weary of introducing new behavior @@ -374,3 +375,5 @@ TODO: Create a basic Element class, which DisplayElement extends. We have a lot of code related to scheduling displaying stuff on the screen, and it'd be nice to keep it more separate from all the basic element logic. (Done!) + +TODO: toString functions for elements! Handy for debugging. diff --git a/tui-lib b/tui-lib index eb3b83f..49eb240 160000 --- a/tui-lib +++ b/tui-lib @@ -1 +1 @@ -Subproject commit eb3b83fa2d56f3c85ac0d5c9b62223f6bd297940 +Subproject commit 49eb24099f0a6088976972df5ecb7c927c78a110 diff --git a/ui.js b/ui.js index b1eb7c4..a3860e9 100644 --- a/ui.js +++ b/ui.js @@ -3071,7 +3071,19 @@ class ContextMenu extends FocusElement { } if (this.visible) { + const newlySelected = this.root.selectedElement this.close() + + // Bad hack: if the menubar is the selected thing, directly select it + // (hence setting its previously selected element to whatever we just + // restored the selection to as the context menu). + const menubar = newlySelected.directAncestors.find( + el => el instanceof Menubar) + if (menubar) { + menubar.select() + } else { + this.selectedBefore.root.select(newlySelected) + } } } -- cgit 1.3.0-6-gf8a5