From df60911c18e812b968aa7da1ad6e0101a6ed439d Mon Sep 17 00:00:00 2001 From: vicky469 <127980880+vicky469@users.noreply.github.com> Date: Mon, 13 Jul 2026 02:20:53 +0800 Subject: [PATCH] fix: clear sidebar context when no active file and adjust toolbar sizing --- docs/releases/2.0.89.md | 10 ++++++++++ manifest.json | 2 +- package.json | 2 +- src/app/workspaceContextController.ts | 18 ++++++++++-------- src/app/workspaceContextPlanner.ts | 14 +++++++++++--- styles.css | 26 ++++++++++++++------------ tests/sidebarIndexContext.test.ts | 20 ++++++++++++++++++++ versions.json | 3 ++- 8 files changed, 69 insertions(+), 26 deletions(-) create mode 100644 docs/releases/2.0.89.md diff --git a/docs/releases/2.0.89.md b/docs/releases/2.0.89.md new file mode 100644 index 0000000..13097a4 --- /dev/null +++ b/docs/releases/2.0.89.md @@ -0,0 +1,10 @@ +# 2.0.89 + +## What's new + +- Keep the sidebar empty when no tab is active so stale notes from previous files are not shown. +- Improve index and note toolbar sizing so file-pinned controls and action buttons are more compact. + +## Notes + +- This release only changes sidebar behavior and styling; it does not alter storage formats. diff --git a/manifest.json b/manifest.json index 8284673..c30ed4f 100755 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "aside", "name": "Aside", - "version": "2.0.88", + "version": "2.0.89", "minAppVersion": "1.12.7", "description": "Side comments for humans and agents.", "author": "vicky", diff --git a/package.json b/package.json index 874a654..3de7a4a 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aside", - "version": "2.0.88", + "version": "2.0.89", "description": "Side comments for humans and agents.", "private": true, "main": "main.js", diff --git a/src/app/workspaceContextController.ts b/src/app/workspaceContextController.ts index 06b0484..f04893c 100644 --- a/src/app/workspaceContextController.ts +++ b/src/app/workspaceContextController.ts @@ -7,7 +7,6 @@ import { resolveWorkspaceFileTargets, resolveWorkspaceLeafTargetInput, shouldHidePublicMarkdownProperties, - shouldIgnoreWorkspaceFileOpen, shouldIgnoreWorkspaceLeafChange, type SidebarUnavailableReason, } from "./workspaceContextPlanner"; @@ -36,6 +35,7 @@ export class WorkspaceContextController { public initializeActiveFiles(activeFile: TFile | null): void { const nextState = resolveWorkspaceFileTargets( + activeFile, activeFile, null, null, @@ -47,16 +47,13 @@ export class WorkspaceContextController { public handleFileOpen(file: TFile | null): void { const activeFile = this.host.app.workspace.getActiveFile(); - if (shouldIgnoreWorkspaceFileOpen(file, activeFile)) { - return; - } void this.syncIndexNoteLeafMode(this.host.app.workspace.getActiveViewOfType(MarkdownView)?.leaf ?? null); this.syncIndexNoteViewClasses(); this.applyWorkspaceFileTargets(resolveWorkspaceTargetInput( file, activeFile, - )); + ), activeFile); } public handleActiveLeafChange(leaf: WorkspaceLeaf | null): void { @@ -64,10 +61,11 @@ export class WorkspaceContextController { if (shouldIgnoreWorkspaceLeafChange(viewType)) { return; } + const workspaceActiveFile = this.host.app.workspace.getActiveFile(); const file = resolveWorkspaceLeafTargetInput( leaf, - this.host.app.workspace.getActiveFile(), + workspaceActiveFile, (value): value is TFile => value instanceof TFile, (filePath) => { const file = this.host.app.vault.getAbstractFileByPath(filePath); @@ -76,7 +74,7 @@ export class WorkspaceContextController { ); void this.syncIndexNoteLeafMode(leaf); this.syncIndexNoteViewClasses(); - this.applyWorkspaceFileTargets(file); + this.applyWorkspaceFileTargets(file, workspaceActiveFile); } public async syncIndexNoteLeafMode(leaf: WorkspaceLeaf | null): Promise { @@ -119,10 +117,14 @@ export class WorkspaceContextController { }); } - private applyWorkspaceFileTargets(file: TFile | null): void { + private applyWorkspaceFileTargets( + file: TFile | null, + workspaceActiveFile: TFile | null, + ): void { const targetVersion = ++this.workspaceTargetVersion; const nextState = resolveWorkspaceFileTargets( file, + workspaceActiveFile, this.host.getActiveMarkdownFile(), this.host.getActiveSidebarFile(), (candidate): candidate is TFile => this.host.isMarkdownCommentableFile(candidate), diff --git a/src/app/workspaceContextPlanner.ts b/src/app/workspaceContextPlanner.ts index 128fc5d..06a8839 100644 --- a/src/app/workspaceContextPlanner.ts +++ b/src/app/workspaceContextPlanner.ts @@ -168,6 +168,7 @@ function isMarkdownWorkspaceLeaf(leaf: unknown): boolean { export function resolveWorkspaceFileTargets( file: T | null, + workspaceActiveFile: T | null, activeMarkdownFile: T | null, activeSidebarFile: T | null, isMarkdownCommentableFile: (file: T | null) => file is T, @@ -175,19 +176,26 @@ export function resolveWorkspaceFileTargets( ): WorkspaceFileTargets { const hasConcreteFile = file !== null; const supportsSidebar = isSidebarSupportedFile(file); + const hasWorkspaceActiveFile = workspaceActiveFile !== null; const nextActiveMarkdownFile = isMarkdownCommentableFile(file) ? file - : activeMarkdownFile; + : hasWorkspaceActiveFile + ? activeMarkdownFile + : null; const nextActiveSidebarFile = supportsSidebar ? file : hasConcreteFile ? null - : activeSidebarFile; + : hasWorkspaceActiveFile + ? activeSidebarFile + : null; const sidebarFile = supportsSidebar ? file : hasConcreteFile ? null - : activeSidebarFile; + : hasWorkspaceActiveFile + ? activeSidebarFile + : null; return { activeMarkdownFile: nextActiveMarkdownFile, diff --git a/styles.css b/styles.css index 00adf50..53e222c 100644 --- a/styles.css +++ b/styles.css @@ -741,21 +741,21 @@ button.aside-tab-button[aria-disabled="true"] { } button.aside-sidebar-file-pin-button { - flex: 0 0 26px; - width: 26px; - min-width: 26px; - max-width: 26px; - height: 26px; - min-height: 26px; - max-height: 26px; + flex: 0 0 22px; + width: 22px; + min-width: 22px; + max-width: 22px; + height: 22px; + min-height: 22px; + max-height: 22px; margin-left: auto; padding: 0; - --icon-size: 13px; + --icon-size: 12px; } .aside-sidebar-toolbar-row.is-note-primary-row .aside-toolbar-icon-button { - width: 26px; - height: 26px; + width: 22px; + height: 22px; border-radius: var(--aside-note-toolbar-radius); margin-bottom: -1px; color: color-mix(in srgb, var(--icon-color, var(--text-faint, var(--text-muted))) 82%, var(--text-muted) 18%); @@ -771,6 +771,8 @@ button.aside-sidebar-file-pin-button { height: 26px; min-height: 26px; max-height: 26px; + --aside-toolbar-control-font-size: 11px; + --icon-size: 13px; border-radius: var(--aside-note-toolbar-radius); background: transparent; box-shadow: none; @@ -1253,8 +1255,8 @@ button.aside-filter-chip { } .aside-sidebar-toolbar.is-note-toolbar .aside-comment-section-add-button svg { - width: 15px; - height: 15px; + width: 13px; + height: 13px; } .aside-comment-section-add-button:hover, diff --git a/tests/sidebarIndexContext.test.ts b/tests/sidebarIndexContext.test.ts index 46b3058..5420964 100644 --- a/tests/sidebarIndexContext.test.ts +++ b/tests/sidebarIndexContext.test.ts @@ -83,6 +83,7 @@ class MockPlugin { const nextState = resolveWorkspaceFileTargets( file, this.activeMarkdownFile, + this.activeMarkdownFile, this.activeSidebarFile, (candidate): candidate is MockFile => !!candidate && candidate.extension === "md" && candidate.path !== ALL_COMMENTS_NOTE_PATH, (candidate): candidate is MockFile => !!candidate && (candidate.extension === "md" || candidate.extension === "pdf"), @@ -269,6 +270,7 @@ test("workspace file targets preserve the last markdown note while pointing the const target = resolveWorkspaceFileTargets( { path: ALL_COMMENTS_NOTE_PATH, extension: "md" }, { path: "last-note.md", extension: "md" }, + { path: "last-note.md", extension: "md" }, null, (file): file is MockFile => !!file && file.extension === "md" && file.path !== ALL_COMMENTS_NOTE_PATH, (file): file is MockFile => !!file && file.extension === "md", @@ -283,6 +285,7 @@ test("workspace file targets preserve the last markdown note while pointing the const target = resolveWorkspaceFileTargets( { path: "docs/file.pdf", extension: "pdf" }, { path: "last-note.md", extension: "md" }, + { path: "last-note.md", extension: "md" }, { path: "docs/note.md", extension: "md" }, (file): file is MockFile => !!file && file.extension === "md" && file.path !== ALL_COMMENTS_NOTE_PATH, (file): file is MockFile => !!file && (file.extension === "md" || file.extension === "pdf"), @@ -297,6 +300,7 @@ test("workspace file targets preserve the current sidebar file when leaf changes const target = resolveWorkspaceFileTargets( null, { path: "last-note.md", extension: "md" }, + { path: "last-note.md", extension: "md" }, { path: ALL_COMMENTS_NOTE_PATH, extension: "md" }, (file): file is MockFile => !!file && file.extension === "md" && file.path !== ALL_COMMENTS_NOTE_PATH, (file): file is MockFile => !!file && file.extension === "md", @@ -310,6 +314,7 @@ test("workspace file targets preserve the current sidebar file when leaf changes test("workspace file targets clear the sidebar file when the active file is unsupported", () => { const target = resolveWorkspaceFileTargets( { path: "docs/board.canvas", extension: "canvas" }, + { path: "docs/file.pdf", extension: "pdf" }, { path: "last-note.md", extension: "md" }, { path: "docs/note.md", extension: "md" }, (file): file is MockFile => !!file && file.extension === "md" && file.path !== ALL_COMMENTS_NOTE_PATH, @@ -321,6 +326,21 @@ test("workspace file targets clear the sidebar file when the active file is unsu assert.equal(target.sidebarFile, null); }); +test("workspace file targets clear when there is no active workspace file", () => { + const target = resolveWorkspaceFileTargets( + null, + null, + { path: "last-note.md", extension: "md" }, + { path: ALL_COMMENTS_NOTE_PATH, extension: "md" }, + (file): file is MockFile => !!file && file.extension === "md" && file.path !== ALL_COMMENTS_NOTE_PATH, + (file): file is MockFile => !!file && file.extension === "md", + ); + + assert.equal(target.activeMarkdownFile, null); + assert.equal(target.activeSidebarFile, null); + assert.equal(target.sidebarFile, null); +}); + test("workspace target input prefers the real active file when the event file is missing", () => { const resolved = resolveWorkspaceTargetInput( null, diff --git a/versions.json b/versions.json index abe9f66..fd234cd 100644 --- a/versions.json +++ b/versions.json @@ -123,5 +123,6 @@ "2.0.85": "1.12.7", "2.0.86": "1.12.7", "2.0.87": "1.12.7", - "2.0.88": "1.12.7" + "2.0.88": "1.12.7", + "2.0.89": "1.12.7" }