From acb6e7bd48e11105b8e57ed703fd75782a2933cc Mon Sep 17 00:00:00 2001 From: Florrie Date: Sun, 15 Sep 2019 18:29:17 -0300 Subject: Jump to top/bottom in context menus Although we don't have any context menu options which start with the letter G yet, if we did, the keyboard selector would (intentionally) take priority and focus that element instead of doing jump to start/ bottom behavior. However, pressing Home/End will always work (once it's implemented). --- todo.txt | 1 + tui-lib | 2 +- ui.js | 14 +++++++++++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/todo.txt b/todo.txt index 6af1370..2163271 100644 --- a/todo.txt +++ b/todo.txt @@ -349,6 +349,7 @@ TODO: If you press any key which should select a particular element of the UI TODO: g/G should work for navigation in context menus! And probably all ListScrollForms, tbh, but I'm kinda weary of introducing new behavior like that to tui-lib. + (Done!) TODO: PageUp/PageDown support is complicated to implement (I've tried) and should come eventually, but for now just make Home/End work as aliases diff --git a/tui-lib b/tui-lib index d8943db..f397462 160000 --- a/tui-lib +++ b/tui-lib @@ -1 +1 @@ -Subproject commit d8943db70aab7e7192040caaf0bbf02d5ddf429c +Subproject commit f3974627bddb9f62132bf54bde3a66c87dbf7b23 diff --git a/ui.js b/ui.js index 972e139..bdc4258 100644 --- a/ui.js +++ b/ui.js @@ -58,6 +58,8 @@ const keyBindings = [ ['isBackspace', telc.isBackspace], ['isMenu', 'm'], ['isMenu', 'f'], + ['isScrollToStart', 'g', {caseless: false}], + ['isScrollToEnd', 'G', {caseless: false}], ['isTogglePause', telc.isSpace], ['isToggleLoop', 'l', {caseless: false}], ['isStop', telc.isEscape], @@ -1216,10 +1218,10 @@ class GrouplikeListingElement extends Form { this.loadParentGrouplike() } else if (telc.isCharacter(keyBuf, '/') || keyBuf[0] === 6) { // '/', ctrl-F this.showJumpElement() - } else if (telc.isCharacter(keyBuf, 'g')) { + } else if (input.isScrollToStart(keyBuf)) { this.form.selectAndShow(this.grouplike.items[0]) this.form.scrollToBeginning() - } else if (telc.isCharacter(keyBuf, 'G')) { + } else if (input.isScrollToEnd(keyBuf)) { this.form.selectAndShow(this.grouplike.items[this.grouplike.items.length - 1]) } else if (keyBuf[0] === 12) { // ctrl-L if (this.grouplike.isTheQueue) { @@ -3049,8 +3051,14 @@ class ContextMenu extends FocusElement { return false } else if (this.keyboardSelector.keyPressed(keyBuf)) { return false + } else if (input.isScrollToStart(keyBuf)) { + this.form.firstInput() + this.form.scrollToBeginning() + } else if (input.isScrollToEnd(keyBuf)) { + this.form.lastInput() + } else { + return super.keyPressed(keyBuf) } - super.keyPressed(keyBuf) } unselected() { -- cgit 1.3.0-6-gf8a5