Repository navigation
Keep a code block as tall when its line scrolls as when it fits #258
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 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
055d841
Keep a code block as tall when its line scrolls as when it fits
rostislavrotaru 65582bc
Start a mouse desktop's scrolling code block at its classic bar's height
rostislavrotaru 7f43022
Measure the site code block's scrollbar as the code block does
rostislavrotaru 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
80 changes: 80 additions & 0 deletions
80
...onents.angular/tests/app/components/code-block/code-block-scroll-height.component.spec.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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /** | ||
| * @license | ||
| * Copyright (c) Noldova. | ||
| * | ||
| * This source code is licensed under the license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| import { page } from "vitest/browser"; | ||
|
|
||
| import { DefaultTheme } from "../../../../src/app/models/default-theme"; | ||
| import { AppearanceFixture } from "../../../../src/testing/services/appearance-fixture"; | ||
| import { CodeBlockHarness } from "../../../fixtures/code-block-harness.fixture"; | ||
|
|
||
| // A one-line block's line, short enough to fit in a phone's column, and one that scrolls there. | ||
| const FITS = "sha256sum TeamRun-0.0.5-linux-x64.deb"; | ||
| const SCROLLS = "Get-FileHash .\\TeamRun-0.0.5-windows-x64.exe -Algorithm SHA256"; | ||
|
|
||
| // A classic sideways scrollbar's height, as the kit draws one. The test browser runs headless, where no scrollbar takes | ||
| // room, so its block measures none; a classic bar's case sets the measured height on the body as the block would. | ||
| const CLASSIC_BAR = 0.375; | ||
|
|
||
| describe("CodeBlockComponent", () => { | ||
| const harness = new CodeBlockHarness(); | ||
| const { renderAsync, changeAsync, find, body, settledAsync } = harness; | ||
| const windowWidth = window.innerWidth; | ||
| const windowHeight = window.innerHeight; | ||
|
|
||
| beforeEach(harness.configure); | ||
|
|
||
| afterEach(async () => { | ||
| await harness.resetAsync(); | ||
| await page.viewport(windowWidth, windowHeight); | ||
| }); | ||
|
|
||
| const rem = (value: number): number => AppearanceFixture.toPixels(value); | ||
| const bar = (): number => body().offsetHeight - body().clientHeight; | ||
| const height = (): number => find("nol-code-block").getBoundingClientRect().height; | ||
| const padding = (): number => Number.parseFloat(getComputedStyle(find(".nol-code-block-body > code")).paddingBottom); | ||
| const shape = (): string => JSON.stringify([height(), body().scrollWidth, body().clientWidth, bar(), padding()]); | ||
|
|
||
| async function renderLineAsync(width: number, mode: (typeof AppearanceFixture.modes)[number], code: string): Promise<void> { | ||
| await page.viewport(width, 800); | ||
| AppearanceFixture.apply(DefaultTheme.theme, mode); | ||
| await renderAsync(); | ||
| await changeAsync(() => { | ||
| harness.host.width.set("calc(100vw - 2.5rem)"); | ||
| harness.host.language.set(null); | ||
| harness.host.code.set(code); | ||
| }); | ||
| await settledAsync("the line", shape); | ||
| } | ||
|
|
||
| for (const width of [375, 1280]) | ||
| for (const mode of AppearanceFixture.modes) | ||
| it(`is as tall with one line that scrolls as with one that fits, where the scrollbar lies over the code, at ${String(width)} pixels, in ${mode.toLowerCase()} mode`, async () => { | ||
| await renderLineAsync(width, mode, FITS); | ||
| const fits = height(); | ||
| const fitsBar = bar(); | ||
| await changeAsync(() => harness.host.code.set(SCROLLS)); | ||
| await settledAsync("the line that scrolls", shape); | ||
|
|
||
| expect([fitsBar, body().scrollWidth > body().clientWidth, bar()]).toEqual([0, width < 600, 0]); | ||
| AppearanceFixture.expectPixels(padding(), rem(0.875)); | ||
| AppearanceFixture.expectPixels(height(), fits); | ||
| }); | ||
|
|
||
| for (const mode of AppearanceFixture.modes) | ||
| it(`gives up a classic scrollbar's measured height from its bottom padding, so with the bar's room it is as tall as a block whose line fits, at 375 pixels, in ${mode.toLowerCase()} mode`, async () => { | ||
| await renderLineAsync(375, mode, FITS); | ||
| const fits = height(); | ||
| await changeAsync(() => harness.host.code.set(SCROLLS)); | ||
| body().style.setProperty("--nol-code-scrollbar-height", `${String(CLASSIC_BAR)}rem`); | ||
| await settledAsync("the line that scrolls over a classic bar", shape); | ||
|
|
||
| expect(body().scrollWidth).toBeGreaterThan(body().clientWidth); | ||
| AppearanceFixture.expectPixels(padding(), rem(0.875 - CLASSIC_BAR)); | ||
| AppearanceFixture.expectPixels(height() + rem(CLASSIC_BAR), fits); | ||
| }); | ||
| }); |
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.