-
Notifications
You must be signed in to change notification settings - Fork 507
fix(ui): restore usable scrolling for one-line code blocks #3170
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
Astro-Han
merged 5 commits into
apache:main
from
MicroGery:fix/single-line-code-scrollbar
Aug 19, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d9898b8
fix(ui): make one-line code blocks horizontally scrollable
MicroGery 15e89b8
fix(ui): name collapsible plaintext code blocks
MicroGery dce234b
fix(ui): address code block review feedback
MicroGery e5b8924
Merge remote-tracking branch 'origin/main' into review/pr-3170
jackwener 46a36de
test(ui): remove stale scrollbar implementation assertion
jackwener 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| import { expect, test, COMPOSER_INPUT } from './fixtures'; | ||
|
|
||
| test('a one-line Markdown code block exposes native and selection horizontal scrolling', async ({ | ||
| window: page, | ||
| }) => { | ||
| await page.setViewportSize({ width: 900, height: 700 }); | ||
| const longLine = Array.from( | ||
| { length: 80 }, | ||
| (_, index) => `word-${String(index).padStart(3, '0')}`, | ||
| ).join(' '); | ||
| const composer = page.locator(COMPOSER_INPUT); | ||
| await composer.fill([ | ||
| 'show these keys', | ||
| '', | ||
| '```', | ||
| 'short-key', | ||
| '```', | ||
| '', | ||
| '```', | ||
| longLine, | ||
| '```', | ||
| ].join('\n')); | ||
| await composer.press('Enter'); | ||
|
|
||
| const codeBlocks = page.locator('.maka-markdown-code[data-maka-code-layout="single-line"]'); | ||
| const viewport = codeBlocks.last().locator('[role="group"]'); | ||
| await expect(viewport).toBeVisible(); | ||
| await expect(page.getByRole('button', { name: '重新生成' })).toHaveCount(1, { | ||
| timeout: 20_000, | ||
| }); | ||
|
|
||
| const metrics = await viewport.evaluate((element) => { | ||
| const node = element as HTMLElement; | ||
| const rect = node.getBoundingClientRect(); | ||
| const code = node.querySelector('code'); | ||
| const line = code?.querySelector(':scope > [data-line]'); | ||
| if (!code || !line) throw new Error('code viewport has no line content'); | ||
| const codeRect = code.getBoundingClientRect(); | ||
| const lineRect = line.getBoundingClientRect(); | ||
| return { | ||
| rect: { x: rect.x, y: rect.y, width: rect.width, height: rect.height }, | ||
| clientWidth: node.clientWidth, | ||
| scrollWidth: node.scrollWidth, | ||
| lineTopInset: lineRect.top - codeRect.top, | ||
| lineBottomInset: codeRect.bottom - lineRect.bottom, | ||
| }; | ||
| }); | ||
| expect(metrics.scrollWidth).toBeGreaterThan(metrics.clientWidth); | ||
| expect(Math.abs(metrics.lineTopInset - metrics.lineBottomInset)).toBeLessThanOrEqual(1); | ||
|
|
||
| const overflowX = await viewport.evaluate((element) => getComputedStyle(element).overflowX); | ||
| expect(overflowX).toBe('auto'); | ||
|
|
||
| const viewportBox = await viewport.boundingBox(); | ||
| if (!viewportBox) throw new Error('native scroll viewport has no visible bounds'); | ||
| await page.mouse.move( | ||
| viewportBox.x + viewportBox.width / 2, | ||
| viewportBox.y + viewportBox.height / 2, | ||
| ); | ||
| await page.mouse.wheel(240, 0); | ||
| await expect.poll( | ||
| () => viewport.evaluate((element) => (element as HTMLElement).scrollLeft), | ||
| ).toBeGreaterThan(0); | ||
| const afterWheelScroll = await viewport.evaluate( | ||
| (element) => (element as HTMLElement).scrollLeft, | ||
| ); | ||
|
|
||
| await viewport.evaluate((element) => { | ||
| (element as HTMLElement).scrollLeft = 0; | ||
| }); | ||
| await viewport.focus(); | ||
| await viewport.press('ArrowRight'); | ||
| await expect.poll( | ||
| () => viewport.evaluate((element) => (element as HTMLElement).scrollLeft), | ||
| ).toBeGreaterThan(0); | ||
| const afterKeyboardScroll = await viewport.evaluate( | ||
| (element) => (element as HTMLElement).scrollLeft, | ||
| ); | ||
|
|
||
| await viewport.evaluate((element) => { | ||
| (element as HTMLElement).scrollLeft = 0; | ||
| window.getSelection()?.removeAllRanges(); | ||
| }); | ||
| const code = viewport.locator('code'); | ||
| const codeBox = await code.boundingBox(); | ||
| if (!codeBox) throw new Error('code line has no visible bounds'); | ||
| const textY = codeBox.y + Math.min(codeBox.height / 2, 18); | ||
| await page.mouse.move(codeBox.x + 24, textY); | ||
| await page.mouse.down(); | ||
| await page.mouse.move(metrics.rect.x + metrics.rect.width + 50, textY, { steps: 20 }); | ||
| await expect.poll( | ||
| () => viewport.evaluate((element) => (element as HTMLElement).scrollLeft), | ||
| ).toBeGreaterThan(0); | ||
| await expect.poll( | ||
| () => viewport.evaluate(() => window.getSelection()?.toString().length ?? 0), | ||
| ).toBeGreaterThan(10); | ||
| const afterSelectionDrag = await viewport.evaluate((element) => ({ | ||
| scrollLeft: (element as HTMLElement).scrollLeft, | ||
| selection: window.getSelection()?.toString() ?? '', | ||
| })); | ||
| await page.mouse.up(); | ||
| expect(afterWheelScroll).toBeGreaterThan(0); | ||
| expect(afterKeyboardScroll).toBeGreaterThan(0); | ||
| expect(afterSelectionDrag.scrollLeft).toBeGreaterThan(0); | ||
| expect(afterSelectionDrag.selection.length).toBeGreaterThan(10); | ||
| }); |
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
26 changes: 25 additions & 1 deletion
26
packages/ui/src/__tests__/message-selection-quote-boundary.test.ts
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
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.
Uh oh!
There was an error while loading. Please reload this page.