Skip to content

fix: keep an input method's words when they replace a selection in Firefox - #5674

Merged
leaf-agent merged 1 commit into
mainfrom
fix/issue-5652
Nov 7, 2026
Merged

leaf-agent merged 1 commit into
mainfrom
fix/issue-5652

Conversation

@leaf-agent

Copy link
Copy Markdown
Collaborator

In Firefox, an input method's composition that starts over selected words in Leaf's text field is dropped. compositionstart names 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 defect field-editor.js's beforeinput handler already works around for typed words. That handler skipped compositions, because a composition's beforeinput can't be cancelled. Now, on a composition's first insertCompositionText over a selection, the editor takes the selected words away itself, so the composition starts at a collapsed caret. The deletion is an input.type.compose.start change, 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's insert_text reaches 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 at 09e524975, before #5409 merged the two tests. The caret assertions themselves needed no change.

Tests:

  • The caret test passes in both engines.
  • test_words_typed_over_formatted_words_replace_them_in_firefox now also puts an input method's words over a whole and a partial selection, and undoes them. Without the field-editor.js change it fails, with the field still holding aa **bold** zz.
  • Also passing: test_render_words_watch.py, the Chromium IME test test_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.js also needed a fix. It settled a leaf-text edit at the field's first announcement, so the deletion's announcement made it miss the composed words that arrive after Firefox's own input, and it reported "aa bold" as words that left the screen. Now a native input that 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

…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
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.

Firefox case of test_a_caret_is_drawn_at_a_lines_end_and_after_a_list_bullet has failed since #5409 added it

1 participant