Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Keep block gutter visible after expanding headings https://github.com/siyuan-note/siyuan/issues/18706

Daniel58d68313aab1
diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.ts
index 1331e13953..1d842c7e81 100644
--- a/app/src/protyle/gutter/index.ts
+++ b/app/src/protyle/gutter/index.ts
@@ -37,6 +37,7 @@ import {
import {removeBlock} from "../wysiwyg/remove";
import {focusBlock, focusByRange, getBlockElementsByRange, getEditorRange, selectBlocksByRange} from "../util/selection";
import {hideElements} from "../ui/hideElements";
+import {shouldHideGutterAfterFold} from "../ui/gutterVisibility";
import {highlightRender} from "../render/highlightRender";
import {blockRender} from "../render/blockRender";
import {
@@ -343,6 +344,7 @@ export class Gutter {
hideElements(["gutter"], protyle);
return;
}
+ let foldStatus = -1;
if (event.altKey && foldElement.getAttribute("data-type") === "NodeHeading") {
foldHeadingGroup(protyle, foldElement, "children").finally(() => {
buttonElement.removeAttribute("disabled");
@@ -394,14 +396,16 @@ export class Gutter {
transaction(protyle, doOperations, undoOperations);
buttonElement.removeAttribute("disabled");
} else {
- const foldStatus = setFold(protyle, foldElement).fold;
+ foldStatus = setFold(protyle, foldElement).fold;
if (foldStatus === 1) {
(buttonElement.firstElementChild as HTMLElement).style.transform = "";
} else if (foldStatus === 0) {
(buttonElement.firstElementChild as HTMLElement).style.transform = "rotate(90deg)";
}
}
- hideElements(["gutter"], protyle);
+ if (shouldHideGutterAfterFold(foldStatus)) {
+ hideElements(["gutter"], protyle);
+ }
hideElements(["select"], protyle);
window.siyuan.menus.menu.remove();
return;
diff --git a/app/src/protyle/ui/gutterVisibility.test.ts b/app/src/protyle/ui/gutterVisibility.test.ts
index b7092bc14f..8086b2ac47 100644
--- a/app/src/protyle/ui/gutterVisibility.test.ts
+++ b/app/src/protyle/ui/gutterVisibility.test.ts
@@ -1,6 +1,6 @@
import {describe, it} from "node:test";
import * as assert from "node:assert/strict";
-import {hideGutterElements} from "./gutterVisibility";
+import {hideGutterElements, shouldHideGutterAfterFold} from "./gutterVisibility";
const createElement = (content: string) => {
const classes = new Set<string>();
@@ -37,3 +37,14 @@ describe("hideGutterElements", () => {
assert.equal(gutter.element.innerHTML, "");
});
});
+
+describe("shouldHideGutterAfterFold", () => {
+ it("展开块后保留块标", () => {
+ assert.equal(shouldHideGutterAfterFold(0), false);
+ });
+
+ it("折叠块或折叠状态未变化时隐藏块标", () => {
+ assert.equal(shouldHideGutterAfterFold(1), true);
+ assert.equal(shouldHideGutterAfterFold(-1), true);
+ });
+});
diff --git a/app/src/protyle/ui/gutterVisibility.ts b/app/src/protyle/ui/gutterVisibility.ts
index e194fcc851..b549d5e1ef 100644
--- a/app/src/protyle/ui/gutterVisibility.ts
+++ b/app/src/protyle/ui/gutterVisibility.ts
@@ -6,3 +6,5 @@ export const hideGutterElements = (elements: HTMLElement[], hidden: boolean) =>
item.innerHTML = "";
});
};
+
+export const shouldHideGutterAfterFold = (foldStatus: number) => foldStatus !== 0;