Repository navigation
fix: keep an input method's words when they replace a selection in Firefox - #5674
Merged
Merged
Conversation
…refox In Firefox, a composition that starts over a selection in the text field's shadow root is dropped: compositionstart names the selected words, the composition commits, and the field still holds the old words. Typed words already had a workaround (field-editor.js's beforeinput handler) but it skipped compositions, whose beforeinput can't be cancelled. The editor now takes the selected words away on the composition's first beforeinput, as an `input.type.compose.start` change so one undo restores them along with the composed words. Playwright's insert_text reaches Firefox as a composition, which is why test_a_caret_is_drawn_at_a_lines_end_and_after_a_list_bullet[firefox_browser] timed out: its select-all-and-replace never replaced. The Firefox typing-over-formatting test now also covers an input method's words and their undo. words_watch.js settled a leaf-text edit at the host's first announcement, so the deletion's announcement hid the composition's result that follows its native input. A native input arriving after the edit settled now reopens it. Closes #5652
This was referenced Nov 7, 2026
Closed
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.
In Firefox, an input method's composition that starts over selected words in Leaf's text field is dropped.
compositionstartnames the selected words as its range, the composition commits, and the field still holds the old words. A bare CodeMirror 6.43.15 page in the same Firefox replaces the selection, and so do a plain textarea and a contenteditable. The loss comes from the field's shadow root, the same Firefox defectfield-editor.js'sbeforeinputhandler already works around for typed words. That handler skipped compositions, because a composition'sbeforeinputcan't be cancelled. Now, on a composition's firstinsertCompositionTextover a selection, the editor takes the selected words away itself, so the composition starts at a collapsed caret. The deletion is aninput.type.compose.startchange, which CodeMirror's history joins with the composed words, so one undo brings back the original text. EditContext fields and updates after the first are left alone.This is why
test_a_caret_is_drawn_at_a_lines_end_and_after_a_list_bullet[firefox_browser]timed out. Playwright'sinsert_textreaches Firefox as a composition, so the test's select-all-and-replace never replaced anything, and the field never shrank to the one line the wait expects. #4844 added that step to the test's predecessor, which already failed at09e524975, before #5409 merged the two tests. The caret assertions themselves needed no change.Tests:
test_words_typed_over_formatted_words_replace_them_in_firefoxnow also puts an input method's words over a whole and a partial selection, and undoes them. Without thefield-editor.jschange it fails, with the field still holdingaa **bold** zz.test_render_words_watch.py, the Chromium IME testtest_a_pointer_send_finishes_the_words_an_input_method_holds,drafts/test_draft_editing.py,drafts/test_composer.py,pnpm run test:runtime,pnpm run check:framework, and pre-commit.tests/words_watch.jsalso needed a fix. It settled aleaf-textedit at the field's first announcement, so the deletion's announcement made it miss the composed words that arrive after Firefox's owninput, and it reported "aa bold" as words that left the screen. Now a nativeinputthat arrives after its field's edit has settled reopens the edit. An earlier attempt that held every composition until its native input broke the Chromium IME test, so the watch change is limited to this reopening.Closes #5652 — automated triage