-
-
Notifications
You must be signed in to change notification settings - Fork 717
fix: prevent FloatingFocusManager from resetting editor selection (#2525) #2664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
611c900
b086c13
a56afee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import { expect } from "@playwright/test"; | ||
| import { test } from "../../setup/setupScript.js"; | ||
| import { AI_URL } from "../../utils/const.js"; | ||
| import { focusOnEditor } from "../../utils/editor.js"; | ||
|
|
||
| const AI_BUTTON_SELECTOR = `[data-test="editwithAI"]`; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make the AI button selector match the rendered component.
Also applies to: 32-35 🤖 Prompt for AI Agents |
||
|
|
||
| test.beforeEach(async ({ page }) => { | ||
| await page.goto(AI_URL); | ||
| }); | ||
|
|
||
| test.describe("AI toolbar button should preserve selection (issue #2525)", () => { | ||
| test("Editor selection must be preserved after clicking the AI toolbar button", async ({ | ||
| page, | ||
| }) => { | ||
| await focusOnEditor(page); | ||
|
|
||
| // Select text in the first paragraph | ||
| await page.keyboard.press("Home"); | ||
| await page.keyboard.press("Shift+End"); | ||
| await page.waitForTimeout(500); | ||
|
|
||
| // Record the PM selection before clicking | ||
| const selBefore = await page.evaluate(() => { | ||
| const pm = (window as any).ProseMirror; | ||
| return { from: pm.state.selection.from, to: pm.state.selection.to }; | ||
| }); | ||
| expect(selBefore.to - selBefore.from).toBeGreaterThan(0); | ||
|
Check failure on line 28 in tests/src/end-to-end/ai/ai-selection.test.ts
|
||
|
|
||
| // Click the AI button using page.mouse to trigger real browser | ||
| // focus-shift behavior (Playwright's locator.click() bypasses it) | ||
| const aiButton = page.locator(AI_BUTTON_SELECTOR); | ||
| await expect(aiButton).toBeVisible(); | ||
| const box = (await aiButton.boundingBox())!; | ||
| await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2); | ||
|
|
||
| // Wait for AI menu to appear | ||
| await page | ||
| .locator(".bn-combobox-input input, .bn-combobox input") | ||
| .waitFor({ state: "visible", timeout: 3000 }); | ||
|
|
||
| // The PM selection must match what we had before clicking. | ||
| // Without skipping refs.setReference for in-editor references while | ||
| // FloatingFocusManager is active, floating-ui inserts a focus-return | ||
| // element into the PM contenteditable, triggering its MutationObserver | ||
| // and resetting the selection. | ||
| const selAfter = await page.evaluate(() => { | ||
| const pm = (window as any).ProseMirror; | ||
| return { from: pm.state.selection.from, to: pm.state.selection.to }; | ||
| }); | ||
| expect(selAfter.from).toBe(selBefore.from); | ||
| expect(selAfter.to).toBe(selBefore.to); | ||
| }); | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.