diff --git a/html_orig/jssrc/soft_keyboard.js b/html_orig/jssrc/soft_keyboard.js new file mode 100644 index 0000000..d0f3619 --- /dev/null +++ b/html_orig/jssrc/soft_keyboard.js @@ -0,0 +1,36 @@ +$.ready(() => { + const input = qs('#softkb-input') + let keyboardOpen = false + + let updateInputPosition = function () { + if (!keyboardOpen) return + + let [x, y] = Screen.gridToScreen(Screen.cursor.x, Screen.cursor.y) + input.style.transform = `translate(${x}px, ${y}px)` + } + + input.addEventListener('focus', () => { + keyboardOpen = true + updateInputPosition() + }) + input.addEventListener('blur', () => (keyboardOpen = false)) + Screen.on('cursor-moved', updateInputPosition) + + window.kbOpen = function openSoftKeyboard (open) { + keyboardOpen = open + updateInputPosition() + if (open) input.focus() + else input.blur() + } + + input.addEventListener('keydown', e => { + if (e.key === 'Backspace') { + e.preventDefault() + e.stopPropagation() + Input.sendString('\b') + } + }) + input.addEventListener('keypress', e => { + e.stopPropagation() + }) +}) diff --git a/html_orig/packjs.sh b/html_orig/packjs.sh index 4aaa34a..737eb63 100755 --- a/html_orig/packjs.sh +++ b/html_orig/packjs.sh @@ -11,4 +11,5 @@ cat jssrc/chibi.js \ jssrc/lang.js \ jssrc/wifi.js \ jssrc/term_* \ - jssrc/term.js | npm run --silent minify > js/app.js + jssrc/term.js \ + jssrc/soft_keyboard.js | npm run --silent minify > js/app.js diff --git a/html_orig/pages/term.php b/html_orig/pages/term.php index ea84d53..91aec4b 100644 --- a/html_orig/pages/term.php +++ b/html_orig/pages/term.php @@ -41,7 +41,9 @@

-
+
+ +