branch canvas, 0caadb6f412855052e4a3276a8411cc36166ea4acpsdqs/unified-input
parent
20165f5306
commit
7d08250f46
Binary file not shown.
@ -0,0 +1,85 @@ |
|||||||
|
$.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() |
||||||
|
} |
||||||
|
|
||||||
|
let lastCompositionString = ''; |
||||||
|
let compositing = false; |
||||||
|
|
||||||
|
let sendInputDelta = function (newValue) { |
||||||
|
let resend = false; |
||||||
|
if (newValue.length > lastCompositionString.length) { |
||||||
|
if (newValue.startsWith(lastCompositionString)) { |
||||||
|
// characters have been added at the end
|
||||||
|
Input.sendString(newValue.substr(lastCompositionString.length)) |
||||||
|
} else resend = true; |
||||||
|
} else if (newValue.length < lastCompositionString.length) { |
||||||
|
if (lastCompositionString.startsWith(newValue)) { |
||||||
|
// characters have been removed at the end
|
||||||
|
Input.sendString('\b'.repeat(lastCompositionString.length - |
||||||
|
newValue.length)) |
||||||
|
} else resend = true; |
||||||
|
} else if (newValue !== lastCompositionString) resend = true; |
||||||
|
|
||||||
|
if (resend) { |
||||||
|
// the entire string changed; resend everything
|
||||||
|
Input.sendString('\b'.repeat(lastCompositionString.length) + |
||||||
|
newValue) |
||||||
|
} |
||||||
|
lastCompositionString = newValue; |
||||||
|
} |
||||||
|
|
||||||
|
input.addEventListener('keydown', e => { |
||||||
|
if (e.key === 'Unidentified') return; |
||||||
|
|
||||||
|
e.preventDefault(); |
||||||
|
input.value = ''; |
||||||
|
|
||||||
|
if (e.key === 'Backspace') Input.sendString('\b') |
||||||
|
else if (e.key === 'Enter') Input.sendString('\x0d') |
||||||
|
}) |
||||||
|
input.addEventListener('input', e => { |
||||||
|
e.stopPropagation(); |
||||||
|
|
||||||
|
if (e.isComposing) { |
||||||
|
sendInputDelta(e.data); |
||||||
|
} else { |
||||||
|
if (e.data) Input.sendString(e.data); |
||||||
|
else if (e.inputType === 'deleteContentBackward') { |
||||||
|
lastCompositionString |
||||||
|
sendInputDelta(''); |
||||||
|
} |
||||||
|
} |
||||||
|
}) |
||||||
|
input.addEventListener('compositionstart', e => { |
||||||
|
lastCompositionString = ''; |
||||||
|
compositing = true; |
||||||
|
}); |
||||||
|
input.addEventListener('compositionend', e => { |
||||||
|
lastCompositionString = ''; |
||||||
|
compositing = false; |
||||||
|
input.value = ''; |
||||||
|
}); |
||||||
|
|
||||||
|
Screen.on('open-soft-keyboard', () => input.focus()) |
||||||
|
}) |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,14 @@ |
|||||||
|
{ |
||||||
|
"name": "html_orig", |
||||||
|
"version": "1.0.0", |
||||||
|
"description": "ESPTerm HTML", |
||||||
|
"license": "UNLICENSED", |
||||||
|
"devDependencies": { |
||||||
|
"babel-minify": "^0.2.0", |
||||||
|
"node-sass": "^4.5.3" |
||||||
|
}, |
||||||
|
"scripts": { |
||||||
|
"minify": "babel-minify $@", |
||||||
|
"sass": "node-sass $@" |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,5 @@ |
|||||||
|
#!/bin/bash |
||||||
|
|
||||||
|
echo "Building css..." |
||||||
|
|
||||||
|
npm run sass -- --output-style compressed sass/app.scss > css/app.css |
@ -0,0 +1,15 @@ |
|||||||
|
#!/bin/bash |
||||||
|
|
||||||
|
echo "Packing js..." |
||||||
|
|
||||||
|
cat jssrc/chibi.js \ |
||||||
|
jssrc/keymaster.js \ |
||||||
|
jssrc/utils.js \ |
||||||
|
jssrc/modal.js \ |
||||||
|
jssrc/notif.js \ |
||||||
|
jssrc/appcommon.js \ |
||||||
|
jssrc/lang.js \ |
||||||
|
jssrc/wifi.js \ |
||||||
|
jssrc/term_* \ |
||||||
|
jssrc/term.js \ |
||||||
|
jssrc/soft_keyboard.js | npm run --silent minify > js/app.js |
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue