diff options
author | Florrie <towerofnix@gmail.com> | 2019-08-25 19:47:12 -0300 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2019-08-25 19:47:12 -0300 |
commit | 1337e00646d1b888db6ad8827faf1db9a0329cf3 (patch) | |
tree | da140a9feddc5489b2f5363d835b5cdd6f602d98 | |
parent | c814d5d140ea2383b7b1719a31abf731753c3fd6 (diff) |
Select already selected option from dropdown menu
...by default.
-rw-r--r-- | ui.js | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/ui.js b/ui.js index 840c7ee..e0ab4f6 100644 --- a/ui.js +++ b/ui.js @@ -1821,7 +1821,8 @@ class InlineListPickerElement extends FocusElement { label: label, action: () => { this.curIndex = index - } + }, + isDefault: index === this.curIndex })) }) } else { @@ -2919,7 +2920,7 @@ class ContextMenu extends FocusElement { this.submenu = null } - show({x = 0, y = 0, items}) { + show({x = 0, y = 0, defaultIndex = 0, items}) { items = items.filter(Boolean) if (!items.length) { return @@ -2951,6 +2952,9 @@ class ContextMenu extends FocusElement { addDividerIfWanted() this.form.addInput(item.element) item.element.showContextMenu = this.showSubmenu + if (item.isDefault) { + this.root.select(item.element) + } } else if (item.divider) { wantDivider = true } else { @@ -2964,12 +2968,17 @@ class ContextMenu extends FocusElement { }) } this.form.addInput(button) + if (item.isDefault) { + this.root.select(button) + } } } this.fixLayout() - this.form.firstInput() + if (!items.some(item => item.isDefault)) { + this.form.firstInput() + } this.keyboardSelector.reset() } |