From de4dcd16ef60483640bf75e5167f240ab7c0e2cc Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Thu, 27 Oct 2022 12:33:15 +0200 Subject: [PATCH] ui keyboard: arrow navigation --- src/client/ui/ui-keyboard.js | 37 ++++++++++++++++++++++++++++++++++++ src/scss/ui/keyboard.scss | 2 +- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/client/ui/ui-keyboard.js b/src/client/ui/ui-keyboard.js index c3ff2e5a..4d14f8e9 100644 --- a/src/client/ui/ui-keyboard.js +++ b/src/client/ui/ui-keyboard.js @@ -210,6 +210,43 @@ class OscKeybard extends UiWidget { case '{space}': str = ' ' break + case '{left}': + this.input.selectionStart = this.input.selectionEnd = this.input.selectionStart - 1 + return + case '{right}': + this.input.selectionStart = this.input.selectionEnd = this.input.selectionStart + 1 + return + case '{up}': + case '{down}': + if (this.display.value.includes('\n')) { + var chars = this.display.value.split('\n').map(x=>x.length + 1), + line = 0, + charCount = 0, + newPos = 0, + posAtLine + + for (let i = 0; i < chars.length; i++) { + charCount += chars[i] + if (charCount > this.input.selectionStart) { + posAtLine = chars[i] - (charCount - this.input.selectionStart) + break + } + line++ + } + line = key === '{up}' ? line - 1 : line + 1 + for (let i = 0; i < line; i++) { + newPos += chars[i] + } + if (posAtLine > chars[line] - 1) posAtLine = chars[line] - 1 + + this.input.selectionStart = + this.input.selectionEnd = newPos + posAtLine + return + } else { + this.input.selectionStart = + this.input.selectionEnd = key === '{up}' ? 0 : this.display.value.length + } + return default: str = key break diff --git a/src/scss/ui/keyboard.scss b/src/scss/ui/keyboard.scss index f36aa5b1..4e50605a 100644 --- a/src/scss/ui/keyboard.scss +++ b/src/scss/ui/keyboard.scss @@ -79,7 +79,7 @@ osc-keyboard { } &.active { - --alpha-fill: 0.3; + --alpha-fill: 0.3!important; } }