mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-25 00:57:42 +00:00
Adds textDidChange 'swallow' to prevent KMW desync
This commit is contained in:
parent
dbbeccebdb
commit
733854e2b5
1 changed files with 16 additions and 0 deletions
|
|
@ -40,6 +40,8 @@ open class InputViewController: UIInputViewController, KeymanWebDelegate {
|
|||
var landscapeConstraint: NSLayoutConstraint?
|
||||
|
||||
private var keymanWeb: KeymanWebViewController
|
||||
|
||||
private var swallowBackspaceTextChange: Bool = false
|
||||
|
||||
open class var isPortrait: Bool {
|
||||
return UIScreen.main.bounds.width < UIScreen.main.bounds.height
|
||||
|
|
@ -190,6 +192,12 @@ open class InputViewController: UIInputViewController, KeymanWebDelegate {
|
|||
}
|
||||
|
||||
open override func textDidChange(_ textInput: UITextInput?) {
|
||||
// Swallows self-triggered calls from emptying the context due to keyboard rules
|
||||
if self.swallowBackspaceTextChange {
|
||||
self.swallowBackspaceTextChange = false
|
||||
return
|
||||
}
|
||||
|
||||
let contextBeforeInput = textDocumentProxy.documentContextBeforeInput ?? ""
|
||||
let contextAfterInput = textDocumentProxy.documentContextAfterInput ?? ""
|
||||
let context = "\(contextBeforeInput)\(contextAfterInput)"
|
||||
|
|
@ -203,6 +211,10 @@ open class InputViewController: UIInputViewController, KeymanWebDelegate {
|
|||
|
||||
setContextState(text: context, range: NSRange(newRange, in: context))
|
||||
}
|
||||
|
||||
@objc func clearSwallowFlag() {
|
||||
self.swallowBackspaceTextChange = false
|
||||
}
|
||||
|
||||
func insertText(_ keymanWeb: KeymanWebViewController, numCharsToDelete: Int, newText: String) {
|
||||
if keymanWeb.isSubKeysMenuVisible {
|
||||
|
|
@ -236,6 +248,10 @@ open class InputViewController: UIInputViewController, KeymanWebDelegate {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.swallowBackspaceTextChange = true
|
||||
// afterDelay 0.01 is not sufficient! 0.02 seems to be enough for an actual delay to register.
|
||||
perform(#selector(self.clearSwallowFlag), with: nil, afterDelay: 0.02)
|
||||
|
||||
if !newText.isEmpty {
|
||||
textDocumentProxy.insertText(newText)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue