From f64bd0252741a749b1f3bc57d79b134ecf42afcb Mon Sep 17 00:00:00 2001 From: Florrie Date: Sun, 3 Jun 2018 15:37:30 -0300 Subject: Escape to exit group --- ui.js | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'ui.js') diff --git a/ui.js b/ui.js index 5177aed..73442d0 100644 --- a/ui.js +++ b/ui.js @@ -312,6 +312,14 @@ class GrouplikeListingElement extends ListScrollForm { this.recordStore = recordStore } + keyPressed(keyBuf) { + if (telc.isEscape(keyBuf)) { + this.loadParentGrouplike() + } else { + return super.keyPressed(keyBuf) + } + } + loadGrouplike(grouplike) { this.grouplike = grouplike this.buildItems(true) @@ -331,13 +339,7 @@ class GrouplikeListingElement extends ListScrollForm { const parent = this.grouplike[parentSymbol] if (parent) { const upButton = new Button('Up (to ' + (parent.name || 'unnamed group') + ')') - upButton.on('pressed', () => { - const oldGrouplike = this.grouplike - this.loadGrouplike(parent) - this.curIndex = this.inputs.findIndex(inp => inp.item === oldGrouplike) || this.firstItemIndex - this.updateSelectedElement() - this.scrollSelectedElementIntoView() - }) + upButton.on('pressed', () => this.loadParentGrouplike()) this.addInput(upButton) } @@ -367,6 +369,21 @@ class GrouplikeListingElement extends ListScrollForm { this.fixLayout() } + loadParentGrouplike() { + if (!this.grouplike) { + return + } + + const parent = this.grouplike[parentSymbol] + if (parent) { + const oldGrouplike = this.grouplike + this.loadGrouplike(parent) + this.curIndex = this.inputs.findIndex(inp => inp.item === oldGrouplike) || this.firstItemIndex + this.updateSelectedElement() + this.scrollSelectedElementIntoView() + } + } + selectAndShow(item) { const index = this.inputs.findIndex(inp => inp.item === item) if (index >= 0) { @@ -385,7 +402,6 @@ class GrouplikeListingElement extends ListScrollForm { get isSelected() { return this.root.selected && this.root.selected.directAncestors.includes(this) } - } class GrouplikeItemElement extends Button { -- cgit 1.3.0-6-gf8a5