Fix input events not working on iOS

cpsdqs/unified-input
cpsdqs 7 years ago
parent 3e743ef397
commit 166003cd0e
Signed by untrusted user: cpsdqs
GPG Key ID: 3F59586BB7448DD1
  1. 16
      jssrc/soft_keyboard.js

@ -56,11 +56,15 @@ window.initSoftKeyboard = function (screen) {
input.addEventListener('keydown', e => { input.addEventListener('keydown', e => {
if (e.key === 'Unidentified') return if (e.key === 'Unidentified') return
e.preventDefault()
input.value = '' input.value = ''
if (e.key === 'Backspace') Input.sendString('\b') if (e.key === 'Backspace') {
else if (e.key === 'Enter') Input.sendString('\x0d') e.preventDefault()
Input.sendString('\b')
} else if (e.key === 'Enter') {
e.preventDefault()
Input.sendString('\x0d')
}
}) })
input.addEventListener('input', e => { input.addEventListener('input', e => {
@ -69,10 +73,12 @@ window.initSoftKeyboard = function (screen) {
if (e.isComposing) { if (e.isComposing) {
sendInputDelta(e.data) sendInputDelta(e.data)
} else { } else {
if (e.data) Input.sendString(e.data) if (e.inputType === 'insertCompositionText') Input.sendString(e.data)
else if (e.inputType === 'deleteContentBackward') { else if (e.inputType === 'deleteContentBackward') {
lastCompositionString = '' lastCompositionString = ''
sendInputDelta('') sendInputDelta('')
} else if (e.inputType === 'insertText') {
// this is a sane event, which means the keypress handler will get it
} }
} }
}) })
@ -80,12 +86,14 @@ window.initSoftKeyboard = function (screen) {
input.addEventListener('compositionstart', e => { input.addEventListener('compositionstart', e => {
lastCompositionString = '' lastCompositionString = ''
compositing = true compositing = true
console.log('compositionstart')
}) })
input.addEventListener('compositionend', e => { input.addEventListener('compositionend', e => {
lastCompositionString = '' lastCompositionString = ''
compositing = false compositing = false
input.value = '' input.value = ''
console.log('compositionend')
}) })
screen.on('open-soft-keyboard', () => input.focus()) screen.on('open-soft-keyboard', () => input.focus())

Loading…
Cancel
Save