Conversation
Sending a message while iOS shows an uncommitted inline prediction corrupts the text - "r u going" is sent as "r u goingoingg to" (TelegramMessenger#1543). The text view already tries to drop pending marked text before send (applyKeyboardAutocorrection / dropAutocorrectioniOS16), but the corruption still happens on iOS 17+, so opt this input out of the inline prediction feature, which UIKit offers for editors that handle text themselves.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the message corruption tracked in TelegramMessenger#1543 (also reported at bugs.telegram.org/c/35202).
What happens
With iOS 17+ inline text predictions enabled, sending a message while a prediction is still uncommitted corrupts the text:
r u going->r u goingoingg tohi my name is josh->hi my name is joshsshoshWhy the obvious fix does not work
The send path already tries to settle the marked text before sending:
ChatControllerNode->richTextInputNode.applyAutocorrection()->Keyboard.applyAutocorrection(textView:)->applyKeyboardAutocorrection()(
submodules/UIKitRuntimeUtils/Source/UIKitRuntimeUtils/UIViewController+Navigation.m), which callsunmarkText()and adjusts the selection;dropAutocorrectioniOS16inChatInputTextNodedoes the same thing.That is not enough on iOS 17+: the corruption still happens with that code in place (a report in TelegramMessenger#1543 confirms it persisted after the equivalent change from TelegramMessenger#1692 was in a build). So this is not fixable by "unmarking" the marked text right before send - which is why this PR takes the other route.
What this changes
Opts the legacy
UITextView-based input out of inline predictions:UITextInputTraits.inlinePredictionTypeis the API Apple documents for turning off inline suggestions in a text-entry area, explicitly recommended for cases where the app provides its own suggestions - which is the case here, since the composer already shows its own suggestion surfaces above the keyboard.Scope: only the legacy text view. The TextKit-2 editor (
RichTextEditor/DocumentCanvasView) implements its own marked-text handling (unmarkText()->commitMarkedText()) and its canvas keepsinlinePredictionType = .yes, so it is untouched and keeps inline predictions working.Testing
I could not build or run this on a device - I do not have access to macOS/Xcode, so please test on an iOS 17+ device before merging. The change is a plain
UITextInputTraitsproperty assignment guarded by@available(iOS 17.0, *), but the behaviour itself (no more corrupted sends) needs a device check.If you would rather keep inline predictions, say so and I will rework it as an opt-in setting instead.