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:
@@ -11,9 +11,10 @@
|
||||
error?: string | null;
|
||||
onOpen: (entry: Backlink) => 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 expanded = $state(true);
|
||||
let { entries, busy = false, error = null, onOpen, onRebuild, expanded = $bindable(true) }: Props = $props();
|
||||
const contentId = $props.id();
|
||||
function collapseTooltip(node: HTMLElement) {
|
||||
return { destroy: attachTooltip(node, () => $t(expanded ? "Collapse backlinks" : "Expand backlinks")) };
|
||||
|
||||
@@ -13,8 +13,9 @@
|
||||
backlinks: Backlink[];
|
||||
session: WorkspaceSession;
|
||||
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>
|
||||
|
||||
<aside class="right">
|
||||
@@ -22,7 +23,7 @@
|
||||
<OutlinePane items={outlineItems} {onJump} />
|
||||
</div>
|
||||
{#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}
|
||||
</aside>
|
||||
|
||||
|
||||
@@ -149,6 +149,7 @@
|
||||
let searchRequest = $state<{ text: string; id: number } | null>(null);
|
||||
let leftOpen = $state(!transferredWindow && DEFAULT_WORKBENCH_LAYOUT.leftOpen);
|
||||
let rightOpen = $state(!transferredWindow && DEFAULT_WORKBENCH_LAYOUT.rightOpen);
|
||||
let backlinksOpen = $state(DEFAULT_WORKBENCH_LAYOUT.backlinksOpen);
|
||||
$effect(() => { if ($pluginSidebar && !transferredWindow) leftOpen = true; });
|
||||
let terminalOpen = $state(false);
|
||||
let documentPanes = $state(initialDocumentPanes());
|
||||
@@ -1177,7 +1178,7 @@
|
||||
try {
|
||||
// The layout stays in localStorage on purpose: per-machine view state that is harmless to lose.
|
||||
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; }
|
||||
layoutReady = true;
|
||||
} catch { error = $t("Could not read your layout. Default layout applies for this window."); }
|
||||
@@ -1210,7 +1211,7 @@
|
||||
$effect(() => {
|
||||
if (!layoutReady || transferredWindow) return;
|
||||
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."); }
|
||||
});
|
||||
|
||||
@@ -1464,6 +1465,7 @@
|
||||
}}
|
||||
showBacklinks={buffer?.kind === "text" && isMarkdownPath(buffer.relPath) && !editorPluginVisible}
|
||||
{backlinks}
|
||||
bind:backlinksOpen
|
||||
{session}
|
||||
onOpenBacklink={(entry) => void openBacklink(entry)}
|
||||
/>
|
||||
|
||||
@@ -6,6 +6,8 @@ export interface WorkbenchLayout {
|
||||
leftWidth: number;
|
||||
rightWidth: number;
|
||||
leftView: "files" | "search" | "bookmarks";
|
||||
/** The Backlinks section below the outline is expanded. */
|
||||
backlinksOpen: boolean;
|
||||
}
|
||||
|
||||
export const DEFAULT_WORKBENCH_LAYOUT: Readonly<WorkbenchLayout> = {
|
||||
@@ -14,6 +16,7 @@ export const DEFAULT_WORKBENCH_LAYOUT: Readonly<WorkbenchLayout> = {
|
||||
leftWidth: 260,
|
||||
rightWidth: 240,
|
||||
leftView: "files",
|
||||
backlinksOpen: true,
|
||||
};
|
||||
|
||||
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),
|
||||
rightWidth: width(value?.rightWidth, DEFAULT_WORKBENCH_LAYOUT.rightWidth),
|
||||
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 }; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user