Skip to content

Fix corrupted messages sent while an inline text prediction is pending (#1543) - #193

Open
musice wants to merge 1 commit into
Swiftgram:masterfrom
musice:fix-1543-inline-predictions
Open

musice wants to merge 1 commit into
Swiftgram:masterfrom
musice:fix-1543-inline-predictions

Conversation

@musice

@musice musice commented Sep 13, 2026

Copy link
Copy Markdown

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 to
  • hi my name is josh -> hi my name is joshsshosh

Why 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 calls unmarkText() and adjusts the selection; dropAutocorrectioniOS16 in ChatInputTextNode does 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:

if #available(iOS 17.0, *) {
    self.inlinePredictionType = .no
}

UITextInputTraits.inlinePredictionType is 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 keeps inlinePredictionType = .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 UITextInputTraits property 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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant