Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: duplicated newlines when using dictation on iOS 18+. #1196

Merged
merged 1 commit into from
Oct 30, 2024

Conversation

jorgemanrubia
Copy link
Member

@jorgemanrubia jorgemanrubia commented Oct 28, 2024

Fix: duplicated newlines when using dictation on iOS 18+.

This fixes a bug that started to happen with iOS 18, where you would get duplicated newlines
after completing the dictation.

The bug happens because, upon dictation completion, iOS sends the sequence of beforeinput events
very quickly. With the insertParagraph ones, it can happen that the internal document range fails
to update, resulting in duplicated newlines and missed content.

This workaround is necessary due to the inability to distinguish text entered in dictation mode, as
iOS WebKit doesn’t trigger composition events during dictation (https://bugs.webkit.org/show_bug.cgi?id=261764).

@jorgemanrubia jorgemanrubia force-pushed the fix-ios-dictation-newlines branch 3 times, most recently from 237205b to b3390da Compare October 28, 2024 12:07
@jorgemanrubia jorgemanrubia marked this pull request as draft October 28, 2024 12:22
@jorgemanrubia jorgemanrubia force-pushed the fix-ios-dictation-newlines branch 4 times, most recently from effdb1b to 29212fd Compare October 28, 2024 15:02
@jorgemanrubia jorgemanrubia marked this pull request as ready for review October 28, 2024 15:09
@jorgemanrubia jorgemanrubia force-pushed the fix-ios-dictation-newlines branch 2 times, most recently from 08fd174 to cd64200 Compare October 28, 2024 15:16
This fixes a bug that started to happen with iOS 18, where you would get duplicated newlines
after completing the dictation.

The bug happens because, upon dictation completion, iOS sends the sequence of `beforeinput` events
very quickly. With the `insertParagraph` ones, it can happen that the internal document range fails
to update, resulting in duplicated newlines and missed content.

This workaround is necessary due to the inability to distinguish text entered in dictation mode, as
iOS WebKit doesn’t trigger composition events during dictation (https://bugs.webkit.org/show_bug.cgi?id=261764).

if (handler) {
this.withEvent(event, handler)
this.scheduleRender()

if (!immmediateRender) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm conservatively applying the patch to only iOS and only in certain scenarios. It would be simpler to just render things synchronously all the times. We should probably just always render synchronously if more of these show up. Scheduled rendering waits for an animation frame to render, which is good to avoid locking screen rendering, but it's problematic when receiving many events in a very quick sequence.

@jorgemanrubia jorgemanrubia merged commit 3a32d87 into main Oct 30, 2024
3 checks passed
@jorgemanrubia jorgemanrubia deleted the fix-ios-dictation-newlines branch October 30, 2024 05:20
jorgemanrubia added a commit to basecamp/rails that referenced this pull request Oct 30, 2024
This updates Trix to 2.1.8, which includes a patch for a dictation
issue in iOS 18+ where it garbles newlines when dictation ends.

See basecamp/trix#1196
jeremy pushed a commit to rails/rails that referenced this pull request Oct 30, 2024
This updates Trix to 2.1.8, which includes a patch for a dictation
issue in iOS 18+ where it garbles newlines when dictation ends.

See basecamp/trix#1196
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.

2 participants