Keep the collapsed Backlinks section after a tab change
The Backlinks section expanded again when the user left a tab and came back. The section lost its state when it closed with its tab. - The workbench layout keeps the state in `backlinksOpen` and saves it with the other layout values. - The user guide describes the control. The outline smoke test and the workbenchLayout unit test check the state. Card e81770bc.
This commit is contained in:
+1
-1
@@ -105,7 +105,7 @@ Read follows CommonMark: a single line break inside a paragraph is a space. To s
|
|||||||
- A workspace file link opens in a new tab and keeps the current document open.
|
- A workspace file link opens in a new tab and keeps the current document open.
|
||||||
- A heading link, such as `guide.md#save-your-work` or `#save-your-work`, puts that heading at the top of the view. A heading near the end of a short document stays lower.
|
- A heading link, such as `guide.md#save-your-work` or `#save-your-work`, puts that heading at the top of the view. A heading near the end of a short document stays lower.
|
||||||
- A wiki link, such as `[[Meeting notes]]`, finds the note by name anywhere in the workspace. If two notes have the same name, use a relative or workspace path.
|
- A wiki link, such as `[[Meeting notes]]`, finds the note by name anywhere in the workspace. If two notes have the same name, use a relative or workspace path.
|
||||||
- The **Backlinks** section below the outline lists notes that link to the current note. Select an entry to open it.
|
- The **Backlinks** section below the outline lists notes that link to the current note. Select an entry to open it. Select the **Backlinks** title to collapse or expand the section. RuneStone keeps that choice for all notes and after a restart.
|
||||||
|
|
||||||
If backlinks look out of date, select **Rebuild note index**. Your Markdown files do not depend on this index.
|
If backlinks look out of date, select **Rebuild note index**. Your Markdown files do not depend on this index.
|
||||||
|
|
||||||
|
|||||||
@@ -11,9 +11,10 @@
|
|||||||
error?: string | null;
|
error?: string | null;
|
||||||
onOpen: (entry: Backlink) => void;
|
onOpen: (entry: Backlink) => void;
|
||||||
onRebuild?: () => void;
|
onRebuild?: () => void;
|
||||||
|
/** The owner keeps this value, so the choice survives when the section closes with its tab. */
|
||||||
|
expanded?: boolean;
|
||||||
};
|
};
|
||||||
let { entries, busy = false, error = null, onOpen, onRebuild }: Props = $props();
|
let { entries, busy = false, error = null, onOpen, onRebuild, expanded = $bindable(true) }: Props = $props();
|
||||||
let expanded = $state(true);
|
|
||||||
const contentId = $props.id();
|
const contentId = $props.id();
|
||||||
function collapseTooltip(node: HTMLElement) {
|
function collapseTooltip(node: HTMLElement) {
|
||||||
return { destroy: attachTooltip(node, () => $t(expanded ? "Collapse backlinks" : "Expand backlinks")) };
|
return { destroy: attachTooltip(node, () => $t(expanded ? "Collapse backlinks" : "Expand backlinks")) };
|
||||||
|
|||||||
@@ -13,8 +13,9 @@
|
|||||||
backlinks: Backlink[];
|
backlinks: Backlink[];
|
||||||
session: WorkspaceSession;
|
session: WorkspaceSession;
|
||||||
onOpenBacklink: (entry: Backlink) => void;
|
onOpenBacklink: (entry: Backlink) => void;
|
||||||
|
backlinksOpen?: boolean;
|
||||||
};
|
};
|
||||||
let { outlineItems, onJump, showBacklinks, backlinks, session, onOpenBacklink }: Props = $props();
|
let { outlineItems, onJump, showBacklinks, backlinks, session, onOpenBacklink, backlinksOpen = $bindable(true) }: Props = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<aside class="right">
|
<aside class="right">
|
||||||
@@ -22,7 +23,7 @@
|
|||||||
<OutlinePane items={outlineItems} {onJump} />
|
<OutlinePane items={outlineItems} {onJump} />
|
||||||
</div>
|
</div>
|
||||||
{#if showBacklinks}
|
{#if showBacklinks}
|
||||||
<Backlinks entries={backlinks} busy={session.indexBusy} error={session.indexError} onOpen={onOpenBacklink} onRebuild={() => void session.rebuildIndex()} />
|
<Backlinks bind:expanded={backlinksOpen} entries={backlinks} busy={session.indexBusy} error={session.indexError} onOpen={onOpenBacklink} onRebuild={() => void session.rebuildIndex()} />
|
||||||
{/if}
|
{/if}
|
||||||
</aside>
|
</aside>
|
||||||
|
|
||||||
|
|||||||
@@ -149,6 +149,7 @@
|
|||||||
let searchRequest = $state<{ text: string; id: number } | null>(null);
|
let searchRequest = $state<{ text: string; id: number } | null>(null);
|
||||||
let leftOpen = $state(!transferredWindow && DEFAULT_WORKBENCH_LAYOUT.leftOpen);
|
let leftOpen = $state(!transferredWindow && DEFAULT_WORKBENCH_LAYOUT.leftOpen);
|
||||||
let rightOpen = $state(!transferredWindow && DEFAULT_WORKBENCH_LAYOUT.rightOpen);
|
let rightOpen = $state(!transferredWindow && DEFAULT_WORKBENCH_LAYOUT.rightOpen);
|
||||||
|
let backlinksOpen = $state(DEFAULT_WORKBENCH_LAYOUT.backlinksOpen);
|
||||||
$effect(() => { if ($pluginSidebar && !transferredWindow) leftOpen = true; });
|
$effect(() => { if ($pluginSidebar && !transferredWindow) leftOpen = true; });
|
||||||
let terminalOpen = $state(false);
|
let terminalOpen = $state(false);
|
||||||
let documentPanes = $state(initialDocumentPanes());
|
let documentPanes = $state(initialDocumentPanes());
|
||||||
@@ -1177,7 +1178,7 @@
|
|||||||
try {
|
try {
|
||||||
// The layout stays in localStorage on purpose: per-machine view state that is harmless to lose.
|
// The layout stays in localStorage on purpose: per-machine view state that is harmless to lose.
|
||||||
const layout = parseWorkbenchLayout(localStorage.getItem(WORKBENCH_LAYOUT_KEY));
|
const layout = parseWorkbenchLayout(localStorage.getItem(WORKBENCH_LAYOUT_KEY));
|
||||||
({ leftOpen, rightOpen, leftWidth, rightWidth, leftView } = layout);
|
({ leftOpen, rightOpen, leftWidth, rightWidth, leftView, backlinksOpen } = layout);
|
||||||
if (transferredWindow) { leftOpen = false; rightOpen = false; }
|
if (transferredWindow) { leftOpen = false; rightOpen = false; }
|
||||||
layoutReady = true;
|
layoutReady = true;
|
||||||
} catch { error = $t("Could not read your layout. Default layout applies for this window."); }
|
} catch { error = $t("Could not read your layout. Default layout applies for this window."); }
|
||||||
@@ -1210,7 +1211,7 @@
|
|||||||
$effect(() => {
|
$effect(() => {
|
||||||
if (!layoutReady || transferredWindow) return;
|
if (!layoutReady || transferredWindow) return;
|
||||||
const saved = { leftOpen: narrow.left ? wide.left : leftOpen, rightOpen: narrow.right ? wide.right : rightOpen };
|
const saved = { leftOpen: narrow.left ? wide.left : leftOpen, rightOpen: narrow.right ? wide.right : rightOpen };
|
||||||
try { saveWorkbenchLayout(localStorage, { ...saved, leftWidth, rightWidth, leftView }); }
|
try { saveWorkbenchLayout(localStorage, { ...saved, leftWidth, rightWidth, leftView, backlinksOpen }); }
|
||||||
catch { error = $t("Could not save your layout. Layout changes apply for this window only."); }
|
catch { error = $t("Could not save your layout. Layout changes apply for this window only."); }
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1464,6 +1465,7 @@
|
|||||||
}}
|
}}
|
||||||
showBacklinks={buffer?.kind === "text" && isMarkdownPath(buffer.relPath) && !editorPluginVisible}
|
showBacklinks={buffer?.kind === "text" && isMarkdownPath(buffer.relPath) && !editorPluginVisible}
|
||||||
{backlinks}
|
{backlinks}
|
||||||
|
bind:backlinksOpen
|
||||||
{session}
|
{session}
|
||||||
onOpenBacklink={(entry) => void openBacklink(entry)}
|
onOpenBacklink={(entry) => void openBacklink(entry)}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ export interface WorkbenchLayout {
|
|||||||
leftWidth: number;
|
leftWidth: number;
|
||||||
rightWidth: number;
|
rightWidth: number;
|
||||||
leftView: "files" | "search" | "bookmarks";
|
leftView: "files" | "search" | "bookmarks";
|
||||||
|
/** The Backlinks section below the outline is expanded. */
|
||||||
|
backlinksOpen: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DEFAULT_WORKBENCH_LAYOUT: Readonly<WorkbenchLayout> = {
|
export const DEFAULT_WORKBENCH_LAYOUT: Readonly<WorkbenchLayout> = {
|
||||||
@@ -14,6 +16,7 @@ export const DEFAULT_WORKBENCH_LAYOUT: Readonly<WorkbenchLayout> = {
|
|||||||
leftWidth: 260,
|
leftWidth: 260,
|
||||||
rightWidth: 240,
|
rightWidth: 240,
|
||||||
leftView: "files",
|
leftView: "files",
|
||||||
|
backlinksOpen: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
function width(value: unknown, fallback: number): number {
|
function width(value: unknown, fallback: number): number {
|
||||||
@@ -29,6 +32,7 @@ export function parseWorkbenchLayout(raw: string | null): WorkbenchLayout {
|
|||||||
leftWidth: width(value?.leftWidth, DEFAULT_WORKBENCH_LAYOUT.leftWidth),
|
leftWidth: width(value?.leftWidth, DEFAULT_WORKBENCH_LAYOUT.leftWidth),
|
||||||
rightWidth: width(value?.rightWidth, DEFAULT_WORKBENCH_LAYOUT.rightWidth),
|
rightWidth: width(value?.rightWidth, DEFAULT_WORKBENCH_LAYOUT.rightWidth),
|
||||||
leftView: ["files", "search", "bookmarks"].includes(value?.leftView) ? value.leftView : DEFAULT_WORKBENCH_LAYOUT.leftView,
|
leftView: ["files", "search", "bookmarks"].includes(value?.leftView) ? value.leftView : DEFAULT_WORKBENCH_LAYOUT.leftView,
|
||||||
|
backlinksOpen: typeof value?.backlinksOpen === "boolean" ? value.backlinksOpen : DEFAULT_WORKBENCH_LAYOUT.backlinksOpen,
|
||||||
};
|
};
|
||||||
} catch { return { ...DEFAULT_WORKBENCH_LAYOUT }; }
|
} catch { return { ...DEFAULT_WORKBENCH_LAYOUT }; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
// Sidebar layout persistence: the hidden outline, resized sidebars, and the navigation view survive layout changes, reloads, and reopened windows.
|
// Sidebar layout persistence: the hidden outline, resized sidebars, the navigation view, and collapsed backlinks survive layout changes, tab changes, reloads, and reopened windows.
|
||||||
import assert from "node:assert/strict";
|
import assert from "node:assert/strict";
|
||||||
import { mockTauri, openPage, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||||
|
|
||||||
await runSmoke("layout/outline", async ({ browser }) => {
|
await runSmoke("layout/outline", async ({ browser }) => {
|
||||||
|
const output = await outputDir("layout/outline");
|
||||||
// Pages share one context, so a reopened window keeps the saved layout.
|
// Pages share one context, so a reopened window keeps the saved layout.
|
||||||
const context = await browser.newContext({ viewport: { width: 1280, height: 800 } });
|
const context = await browser.newContext({ viewport: { width: 1280, height: 800 } });
|
||||||
// Unknown commands return null, as the original mock did.
|
// Unknown commands return null, as the original mock did.
|
||||||
await mockTauri(context, {
|
await mockTauri(context, {
|
||||||
strict: false,
|
strict: false,
|
||||||
commands: test => ({
|
commands: test => ({
|
||||||
...test.workspace({ root: "D:\\LayoutTest", files: { "note.md": "# Layout test\n\nA note.\n" } }),
|
...test.workspace({ root: "D:\\LayoutTest", files: { "note.md": "# Layout test\n\nA note.\n", "data.txt": "Plain text.\n" } }),
|
||||||
plugins_snapshot: () => ({ root: "D:\\LayoutTest\\plugins", plugins: [] }),
|
plugins_snapshot: () => ({ root: "D:\\LayoutTest\\plugins", plugins: [] }),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
@@ -32,11 +33,15 @@ await runSmoke("layout/outline", async ({ browser }) => {
|
|||||||
async function widths() {
|
async function widths() {
|
||||||
return page.locator(".shell").evaluate(element => [element.style.getPropertyValue("--left"), element.style.getPropertyValue("--right")]);
|
return page.locator(".shell").evaluate(element => [element.style.getPropertyValue("--left"), element.style.getPropertyValue("--right")]);
|
||||||
}
|
}
|
||||||
|
async function quickOpen(name) {
|
||||||
|
await page.keyboard.press("Control+p");
|
||||||
|
await page.getByRole("textbox", { name: "Find a file" }).fill(name);
|
||||||
|
await page.getByRole("dialog").getByRole("button").filter({ hasText: name }).click();
|
||||||
|
await page.locator(`[role="tab"][data-path="${name}"][aria-selected="true"]`).waitFor();
|
||||||
|
}
|
||||||
await reopen();
|
await reopen();
|
||||||
await page.getByText("LayoutTest", { exact: true }).waitFor();
|
await page.getByText("LayoutTest", { exact: true }).waitFor();
|
||||||
await page.keyboard.press("Control+p");
|
await quickOpen("note.md");
|
||||||
await page.getByRole("textbox", { name: "Find a file" }).fill("note.md");
|
|
||||||
await page.getByRole("dialog").getByRole("button").filter({ hasText: "note.md" }).click();
|
|
||||||
await page.locator(".cm-content").waitFor();
|
await page.locator(".cm-content").waitFor();
|
||||||
await page.getByRole("button", { name: "Hide outline", exact: true }).click();
|
await page.getByRole("button", { name: "Hide outline", exact: true }).click();
|
||||||
await page.keyboard.press("Control+e");
|
await page.keyboard.press("Control+e");
|
||||||
@@ -75,6 +80,24 @@ await runSmoke("layout/outline", async ({ browser }) => {
|
|||||||
await page.getByRole("button", { name: "Show outline", exact: true }).click();
|
await page.getByRole("button", { name: "Show outline", exact: true }).click();
|
||||||
assert.deepEqual(await widths(), resized);
|
assert.deepEqual(await widths(), resized);
|
||||||
console.log("PASS: collapsed sidebars retain their sizes and navigation view");
|
console.log("PASS: collapsed sidebars retain their sizes and navigation view");
|
||||||
|
|
||||||
|
// Card e81770bc: collapsed backlinks stay collapsed while a tab without backlinks is active, and after a window reopen.
|
||||||
|
const backlinks = () => page.getByRole("button", { name: /^Backlinks \d+$/ });
|
||||||
|
await quickOpen("note.md");
|
||||||
|
await backlinks().click();
|
||||||
|
assert.equal(await backlinks().getAttribute("aria-expanded"), "false");
|
||||||
|
await quickOpen("data.txt");
|
||||||
|
await backlinks().waitFor({ state: "detached" });
|
||||||
|
await quickOpen("note.md");
|
||||||
|
assert.equal(await backlinks().getAttribute("aria-expanded"), "false");
|
||||||
|
await page.screenshot({ path: `${output}/backlinks-collapsed-after-tab-change.png` });
|
||||||
|
await reopen();
|
||||||
|
await quickOpen("note.md");
|
||||||
|
assert.equal(await backlinks().getAttribute("aria-expanded"), "false");
|
||||||
|
await backlinks().click();
|
||||||
|
assert.equal(await backlinks().getAttribute("aria-expanded"), "true");
|
||||||
|
assert.equal(await page.evaluate(() => JSON.parse(localStorage.getItem("runestone.workbenchLayout")).backlinksOpen), true);
|
||||||
|
console.log("PASS: collapsed backlinks survive a tab change and a window reopen");
|
||||||
errors.push(...page.errors);
|
errors.push(...page.errors);
|
||||||
assert.deepEqual(errors, []);
|
assert.deepEqual(errors, []);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -10,18 +10,20 @@ test("missing and damaged layouts use defaults", () => {
|
|||||||
|
|
||||||
test("invalid layout fields do not discard valid collapsed states", () => {
|
test("invalid layout fields do not discard valid collapsed states", () => {
|
||||||
for (const leftWidth of [0, -1, 159, 481, "260", null]) {
|
for (const leftWidth of [0, -1, 159, 481, "260", null]) {
|
||||||
assert.deepEqual(parseWorkbenchLayout(JSON.stringify({ leftOpen: false, rightOpen: false, leftWidth, rightWidth: 320, leftView: "unknown" })), {
|
assert.deepEqual(parseWorkbenchLayout(JSON.stringify({ leftOpen: false, rightOpen: false, leftWidth, rightWidth: 320, leftView: "unknown", backlinksOpen: "false" })), {
|
||||||
...DEFAULT_WORKBENCH_LAYOUT, leftOpen: false, rightOpen: false, rightWidth: 320,
|
...DEFAULT_WORKBENCH_LAYOUT, leftOpen: false, rightOpen: false, rightWidth: 320,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
assert.deepEqual(parseWorkbenchLayout('{"leftOpen":"false","rightOpen":0}'), DEFAULT_WORKBENCH_LAYOUT);
|
assert.deepEqual(parseWorkbenchLayout('{"leftOpen":"false","rightOpen":0}'), DEFAULT_WORKBENCH_LAYOUT);
|
||||||
|
// A layout from an older version has no backlinks field. The section starts expanded.
|
||||||
|
assert.equal(parseWorkbenchLayout('{"leftOpen":false}').backlinksOpen, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("layout survives storage round trips with hidden panels and all navigation views", () => {
|
test("layout survives storage round trips with hidden panels, all navigation views, and collapsed backlinks", () => {
|
||||||
const store = new Map<string, string>();
|
const store = new Map<string, string>();
|
||||||
for (const leftView of ["files", "search", "bookmarks"] as const) {
|
for (const leftView of ["files", "search", "bookmarks"] as const) {
|
||||||
for (const leftWidth of [160, 321.5, 480]) {
|
for (const [leftWidth, backlinksOpen] of [[160, false], [321.5, true], [480, false]] as const) {
|
||||||
const layout = { leftOpen: false, rightOpen: false, leftWidth, rightWidth: 400, leftView };
|
const layout = { leftOpen: false, rightOpen: false, leftWidth, rightWidth: 400, leftView, backlinksOpen };
|
||||||
saveWorkbenchLayout({ setItem: (key, value) => { store.set(key, value); } }, layout);
|
saveWorkbenchLayout({ setItem: (key, value) => { store.set(key, value); } }, layout);
|
||||||
assert.deepEqual(parseWorkbenchLayout(store.get(WORKBENCH_LAYOUT_KEY)!), layout);
|
assert.deepEqual(parseWorkbenchLayout(store.get(WORKBENCH_LAYOUT_KEY)!), layout);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user