Keep the selection when a drag crosses a custom attachment - #1205
Keep the selection when a drag crosses a custom attachment#1205lyubomir-bozhinov wants to merge 1 commit into
Conversation
e7d0de0 to
cf3c9d7
Compare
There was a problem hiding this comment.
Pull request overview
Fixes a Firefox (Gecko) selection bug where dragging a text selection across a contenteditable="false" custom attachment (mentions) collapses the selection to zero ranges by making custom Action Text attachments selectable as a single unit inside the editor.
Changes:
- Add an editor-scoped
user-select: allrule for custom Action Text attachments to keep drag-selection intact in Gecko. - Add a Playwright browser test that performs a real mouse drag across a mention and asserts selection is preserved, plus a plain-text control case.
Tip
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/browser/tests/prompts/selection_across_mention.test.js | Adds a cross-browser regression test for drag-selection spanning a mention attachment. |
| app/assets/stylesheets/lexxy-content.css | Applies an editor-only user-select: all workaround to custom Action Text attachments to prevent Gecko from dropping the selection. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
cf3c9d7 to
ff35957
Compare
Dragging a selection across a mention wiped the whole selection in Firefox: the drag ended with no range at all, so nothing was selected and the content could not be copied or replaced. Gecko will not extend a selection across a contenteditable="false" island unless the island is selectable as a single unit. Marking custom attachments user-select: all makes the selection span them, and the mention's text is included in it. Scope the rule to the editor (lexxy-editor &) so it does not change text selection in rendered, read-only Action Text content, which has no contenteditable island and so never hits the Gecko bug.
ff35957 to
c561909
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (1)
app/assets/stylesheets/lexxy-content.css:490
- This nested selector requires a
.lexxy-contentdescendant inside<lexxy-editor>(effectivelylexxy-editor :where(.lexxy-content) action-text-attachment…). In the actual editor DOM,<lexxy-editor>itself owns.lexxy-contentand its content child is.lexxy-editor__content, so the rule does not match and the Firefox workaround is inactive. Match attachments whose subject is a descendant of the editor instead, or move this rule to a top-level editor selector.
lexxy-editor & {
|
Copilot's latest pass suppressed a comment claiming the The claim rests on desugaring Measured in the browser on this branch, with a mention in the editor and the same markup in a plain
So the workaround is active where it should be and stays out of the rendered view, which was the scoping requirement. The regression test is consistent with that: reverting only this CSS makes the drag-across-a-mention test fail on Chromium and Firefox, and restoring it makes it pass. Happy to switch to an explicit top-level editor selector if that reads better to you — it would resolve to the same thing, just without depending on |
Fixes #1148.
The bug
Dragging a selection across a mention wiped the entire selection in Firefox. The drag ended with no range at all — nothing highlighted, nothing to copy or replace.
Hello @Zacharias world"Hello \n world", 1 range"", 0 ranges, collapsedA drag across plain text in the same editor selects normally in Gecko, so the mention is what breaks it.
Why
Gecko will not extend a selection across a
contenteditable="false"island unless the island is selectable as a single unit; it abandons the selection instead. Marking custom attachmentsuser-select: allmakes them span-able, and the mention's text is included in the selection.Two other suspects were ruled out first — neither changed the outcome:
draggable="true"on the attachment (setting it tofalsemade no difference)display: inline-flex(inline-blockandinlineboth still failed)The fix
user-select: allon custom attachments, following the existing@supportspattern in this file.The rule is scoped to the editor with the
lexxy-editor &nesting this file already uses (see the:not(lexxy-editor &)block above). Rendered, read-only Action Text has nocontenteditableisland and so never hits the Gecko bug — it must keep normal text selection, so the workaround must not reach it.Inside the editor there is no visual change: before/after screenshots of a selected mention are pixel-identical, and clicking a mention still selects the node as it did before.
Tests
test/browser/tests/prompts/selection_across_mention.test.js, driven with a real mouse drag:Verified on Chromium, Firefox and WebKit.
prompts/andattachments/are green on Firefox;yarn lintandyarn testare clean.