-
-
Notifications
You must be signed in to change notification settings - Fork 725
fix: no more scrolling to top when opening AI menu #2503
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import { expect } from "@playwright/test"; | ||
| import { test } from "../../setup/setupScript.js"; | ||
| import { AI_URL, EDITOR_SELECTOR } from "../../utils/const.js"; | ||
|
|
||
| // Use a small viewport so the editor content requires scrolling. | ||
| test.use({ viewport: { width: 800, height: 400 } }); | ||
|
|
||
| test.beforeEach(async ({ page }) => { | ||
| await page.goto(AI_URL); | ||
| }); | ||
|
|
||
| test.describe("AI Menu Scroll Regression", () => { | ||
| test("opening the AI menu should not scroll the page to the top", async ({ | ||
| page, | ||
| }) => { | ||
| // Wait for the editor to be ready | ||
| await page.waitForSelector(EDITOR_SELECTOR); | ||
|
|
||
| // Click on the last paragraph so the cursor is near the bottom of the content | ||
| const lastParagraph = page | ||
| .locator("[data-content-type='paragraph']") | ||
| .last(); | ||
| await lastParagraph.click(); | ||
|
|
||
| // Ensure the page is scrolled down (editor puts cursor near bottom of content) | ||
| // We scroll down explicitly to make sure we're not at the top | ||
| await page.evaluate(() => { | ||
| window.scrollTo(0, document.body.scrollHeight); | ||
| }); | ||
| await page.waitForTimeout(200); | ||
|
|
||
| // Record the scroll position before opening the AI menu | ||
| const scrollYBefore = await page.evaluate(() => window.scrollY); | ||
|
|
||
| // Sanity check: we should actually be scrolled down | ||
| expect(scrollYBefore).toBeGreaterThan(0); | ||
|
|
||
| // Open the AI menu via the slash command | ||
| // First, focus back on the editor at the last paragraph | ||
| await lastParagraph.click(); | ||
| await page.waitForTimeout(100); | ||
|
|
||
| // Type /ai to open the slash menu and select the AI option | ||
| await page.keyboard.type("/ai", { delay: 50 }); | ||
| await page.waitForTimeout(300); | ||
|
|
||
| // Wait for the suggestion menu to appear | ||
| const suggestionMenu = page.locator(".bn-suggestion-menu"); | ||
| await suggestionMenu.waitFor({ state: "visible", timeout: 3000 }); | ||
|
|
||
| // Click the AI suggestion menu item to open the AI menu | ||
| const aiMenuItem = suggestionMenu | ||
| .locator(".bn-suggestion-menu-item") | ||
| .first(); | ||
| await aiMenuItem.click(); | ||
|
|
||
| // Wait for the AI menu (combobox input) to appear | ||
| const aiMenuInput = page.locator( | ||
| ".bn-combobox-input input, .bn-combobox input", | ||
| ); | ||
| await aiMenuInput.waitFor({ state: "visible", timeout: 3000 }); | ||
|
|
||
| // Brief wait for any scroll side effects to take place | ||
| await page.waitForTimeout(300); | ||
|
|
||
| // Screenshot after opening AI menu | ||
| expect(await page.screenshot()).toMatchSnapshot( | ||
| "ai_menu_scroll_position.png", | ||
| ); | ||
|
|
||
| // Check that the scroll position has not jumped to the top | ||
| const scrollYAfter = await page.evaluate(() => window.scrollY); | ||
| expect(scrollYAfter).toBeGreaterThan(0); | ||
| expect(scrollYAfter).toBeGreaterThanOrEqual(scrollYBefore * 0.2); | ||
|
|
||
| // Verify the AI menu input is actually focused | ||
| await expect(aiMenuInput).toBeFocused(); | ||
| }); | ||
| }); |
Binary file added
BIN
+77.8 KB
.../end-to-end/ai/ai.test.ts-snapshots/ai-menu-scroll-position-chromium-darwin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+45.8 KB
...c/end-to-end/ai/ai.test.ts-snapshots/ai-menu-scroll-position-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+73.1 KB
...rc/end-to-end/ai/ai.test.ts-snapshots/ai-menu-scroll-position-firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+195 KB
...src/end-to-end/ai/ai.test.ts-snapshots/ai-menu-scroll-position-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is sort of a smell no? This is equivalent to enabling it, but it doesn't feel right.
Shouldn't we always render the focus manager and just toggle the
disabledprop?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, I improved this in latest commit:
TableCellPopovercan be removed? it's not used anywhere afaikThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first I was confused why you needed this, but then it made sense that you needed to pass through these props. I think this is fine for now, and is explicit.
We don't need
TableCellPopover, I think it stayed from the refactor. I removed it