Fixes issues with context reset ops.

This commit is contained in:
jahorton 2019-05-08 09:10:20 +07:00
parent 733854e2b5
commit d9c48d2723
5 changed files with 21 additions and 0 deletions

View file

@ -210,6 +210,8 @@ open class InputViewController: UIInputViewController, KeymanWebDelegate {
}
setContextState(text: context, range: NSRange(newRange, in: context))
// Within the app, this is triggered after every keyboard input.
// We should NOT call .resetContext() here for this reason.
}
@objc func clearSwallowFlag() {
@ -429,8 +431,13 @@ open class InputViewController: UIInputViewController, KeymanWebDelegate {
func clearText() {
setContextState(text: nil, range: NSRange(location: 0, length: 0))
keymanWeb.resetContext()
log.info("Cleared text.")
}
func resetContext() {
keymanWeb.resetContext()
}
func setContextState(text: String?, range: NSRange) {
// Check for any LTR or RTL marks at the context's start; if they exist, we should

View file

@ -195,6 +195,10 @@ extension KeymanWebViewController {
text = text.replacingOccurrences(of: "\n", with: "\\n")
webView!.evaluateJavaScript("setKeymanVal('\(text)');", completionHandler: nil)
}
func resetContext() {
webView!.evaluateJavaScript("keyman.interface.resetContext();", completionHandler: nil)
}
func setDeviceType(_ idiom: UIUserInterfaceIdiom) {
let type: String

View file

@ -906,6 +906,10 @@ public class Manager: NSObject, HTTPDownloadDelegate, UIGestureRecognizerDelegat
func clearText() {
inputViewController.clearText()
}
func resetContext() {
inputViewController.resetContext()
}
func setContextState(text: String?, range: NSRange) {
inputViewController.setContextState(text: text, range: range)

View file

@ -117,6 +117,7 @@ public class TextField: UITextField, KeymanResponder {
length: offset(from: textRange.start, to: textRange.end))
Manager.shared.setContextState(text: self.text, range: newRange)
Manager.shared.resetContext()
}
}
@ -129,6 +130,7 @@ public class TextField: UITextField, KeymanResponder {
length: offset(from: range.start, to: range.end))
Manager.shared.setContextState(text: self.text, range: newRange)
Manager.shared.resetContext()
}
}
@ -165,6 +167,7 @@ public class TextField: UITextField, KeymanResponder {
length: offset(from: textRange.start, to: textRange.end))
Manager.shared.setContextState(text: text, range: newRange)
Manager.shared.resetContext()
shouldUpdateKMText = false
}
}

View file

@ -110,12 +110,14 @@ public class TextView: UITextView, KeymanResponder {
}
Manager.shared.inputViewController.setContextState(text: self.text, range: selectedRange)
Manager.shared.resetContext()
}
}
public override var selectedTextRange: UITextRange? {
didSet {
Manager.shared.setContextState(text: self.text, range: selectedRange)
Manager.shared.resetContext()
}
}
@ -272,6 +274,7 @@ extension TextView: UITextViewDelegate {
if shouldUpdateKMText {
// Catches copy/paste operations
Manager.shared.setContextState(text: textView.text, range: textView.selectedRange)
Manager.shared.resetContext()
shouldUpdateKMText = false
}
}