Don’t leave line selected when switching blobs

Fixes #906

Signed-off-by: Thomas Scholtes <geigerzaehler@axiom.fm>
This commit is contained in:
Thomas Scholtes
2023-07-07 07:41:51 +02:00
parent e0e659f54a
commit 092f8ad774
3 changed files with 14 additions and 5 deletions
+2 -1
View File
@@ -63,9 +63,10 @@
</style>
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<div
{title}
role="button"
tabindex="0"
on:click
class="square-button"
class:active
+4 -1
View File
@@ -27,7 +27,10 @@
$: content = highlighted ? lineNumbersGutter(highlighted) : undefined;
let selectedLineId: string | undefined = undefined;
updateSelectedLineId();
$: {
content;
updateSelectedLineId();
}
function updateSelectedLineId() {
const fragmentId = window.location.hash.substr(1);
+8 -3
View File
@@ -101,19 +101,24 @@ test("source file highlighting", async ({ page }) => {
test("navigate line numbers", async ({ page }) => {
await page.goto(`${markdownUrl}/tree/main/cheatsheet.md`);
await page.locator('text="Plain"').click();
await page.getByRole("button", { name: "Plain" }).click();
await page.locator('[href="#L5"]').click();
await page.getByRole("link", { name: "5", exact: true }).click();
await expect(page.locator("#L5")).toHaveClass("line highlight");
await expect(page).toHaveURL(`${markdownUrl}/tree/main/cheatsheet.md#L5`);
await expectUrlPersistsReload(page);
await expect(page.locator("#L5")).toHaveClass("line highlight");
await page.locator('[href="#L30"]').click();
await page.getByRole("link", { name: "30", exact: true }).click();
await expect(page.locator("#L5")).not.toHaveClass("line highlight");
await expect(page.locator("#L30")).toHaveClass("line highlight");
await expect(page).toHaveURL(`${markdownUrl}/tree/main/cheatsheet.md#L30`);
// Check that we go back to the Markdown view when navigating to a different
// file.
await page.getByRole("link", { name: "footnotes.md" }).click();
await expect(page.getByRole("button", { name: "Plain" })).toBeVisible();
});
test("navigate deep file hierarchies", async ({ page }) => {