Skip to content

Commit

Permalink
Fix bug with dictation on iOS 18+
Browse files Browse the repository at this point in the history
Dictation on iOS does not trigger composition events (https://bugs.webkit.org/show_bug.cgi?id=261764). Instead, it
triggers `beforeinput` events with `insertText`. During the dictation phase, it keeps the range anchored to the
cursor, and iOS may modify past text as new text adds context.

Once dictation is stopped, it starts sending `insertText` events with word fragments. When a past fragment is
altered, iOS sends a `beforeinput` event where `inputType` is null. In this case, perform a synchronous render
operation to set the editor to the correct state. Otherwise, scheduled render requests can process invalid
ranges and mess with the editor contents.
  • Loading branch information
jorgemanrubia committed Oct 4, 2024
1 parent 2b7f980 commit 776e1ce
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/trix/controllers/level_2_input_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ export default class Level2InputController extends InputController {
beforeinput(event) {
const handler = this.constructor.inputTypes[event.inputType]

// Handles bug with Siri dictation on iOS 18+.
if (!event.inputType) {
this.render()
}

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

0 comments on commit 776e1ce

Please sign in to comment.