Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/assets/stylesheets/lexxy-content.css
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,17 @@
position: relative;
white-space: normal;

/* Gecko drops the whole selection when a drag crosses a contenteditable="false"
island unless it is selectable as a single unit. Editor-only: the rendered
view has no contenteditable and must keep normal text selection. */
lexxy-editor & {
-webkit-user-select: all;

@supports (user-select: all) {
user-select: all;
}
}

img {
block-size: var(--lexxy-attachment-image-size);
border-radius: 50%;
Expand Down
47 changes: 47 additions & 0 deletions test/browser/tests/prompts/selection_across_mention.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { test } from "../../test_helper.js"
import { expect } from "@playwright/test"

const MENTION = '<action-text-attachment sgid="test-sgid-zacharias" content-type="application/vnd.actiontext.mention" content="&lt;span class=&quot;person person--inline&quot;&gt;Zacharias&lt;/span&gt;"></action-text-attachment>'

async function dragAcrossParagraph(page, editor) {
const paragraph = await editor.content.locator("p").first().boundingBox()
const y = paragraph.y + paragraph.height / 2

await page.mouse.move(paragraph.x + 4, y)
await page.mouse.down()
await page.mouse.move(paragraph.x + paragraph.width - 4, y, { steps: 15 })
await page.mouse.up()
await editor.flush()
}

function selectedText(page) {
return page.evaluate(() => window.getSelection().toString())
}

test.describe("Selecting content that contains a mention", () => {
test.beforeEach(async ({ page }) => {
await page.goto("/mentions.html")
await page.waitForSelector("lexxy-editor[connected]")
})

test("dragging across a mention selects the surrounding text", async ({ page, editor }) => {
await editor.setValue(`<p>Hello ${MENTION} world</p>`)
await editor.flush()

await dragAcrossParagraph(page, editor)

const selection = await selectedText(page)
expect(selection).toContain("Hello")
expect(selection).toContain("world")
expect(selection).toContain("Zacharias")
})

test("dragging across plain text still selects it", async ({ page, editor }) => {
await editor.setValue("<p>Hello there world</p>")
await editor.flush()

await dragAcrossParagraph(page, editor)

expect(await selectedText(page)).toContain("Hello there world")
})
})