Created
July 23, 2015 21:15
-
-
Save thebnich/c0e5731f9e25b24b1168 to your computer and use it in GitHub Desktop.
Autocomplete flicker fix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Client/Frontend/Widgets/AutocompleteTextField.swift b/Client/Frontend/Widgets/AutocompleteTextField.swift | |
index 5ca98a8..0ad478a 100644 | |
--- a/Client/Frontend/Widgets/AutocompleteTextField.swift | |
+++ b/Client/Frontend/Widgets/AutocompleteTextField.swift | |
@@ -133,10 +133,24 @@ class AutocompleteTextField: UITextField, UITextFieldDelegate { | |
} | |
override func insertText(text: String) { | |
+ // Before replacing the string, cache the existing autocompletion so we can reuse it | |
+ // immediately if the user continues the same string. | |
+ var reuseCompletion = false | |
+ let suggestion = self.text | |
+ if completionActive { | |
+ let endingString = self.text.substringFromIndex(advance(self.text.startIndex, enteredTextLength)) | |
+ reuseCompletion = endingString.startsWith(text) | |
+ } | |
+ | |
removeCompletion() | |
super.insertText(text) | |
enteredTextLength = count(self.text) | |
+ // The user entered a character that's still part of the autocomplete result, so apply it now. | |
+ if reuseCompletion { | |
+ setAutocompleteSuggestion(suggestion) | |
+ } | |
+ | |
notifyTextChanged?() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @brian ,
I agree flicker fix is little bit complicated and I reach same patch with
insertText
before. But due to some buginsertText
not called in iOS9. We do not haveself.text
in our control in iOS9. Before inserting text we removed completionremoveCompletion()
and thensuper.insertText(text)
to enter text without completion and then we set theautoCompletion
.This all happen same time so flicker issue will remove.I have tried that with
shouldChangeCharacters
where I have simply removed completion and ontextDidChange
event I have set the AutoCompletion. But in betweentextField
get updated and we get flicker issue again not because of database delay this time buttextField
get update.We need to decide before
textDidChange
event to remove or not remove completion. We should not remove completion each time with our iOS9 fix.Need your help if we can simplify further. Thanks for your help.