Skip to content

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

:art: Improve block collapse and expansion operations (#10717)

Yingyi / 颖逸e922c402c8a8
diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts
index 33006cb59b..1654d91212 100644
--- a/app/src/menus/protyle.ts
+++ b/app/src/menus/protyle.ts
@@ -1870,9 +1870,8 @@ export const setFold = (protyle: IProtyle, nodeElement: Element, isOpen?: boolea
if (nodeElement.getAttribute("data-type") === "NodeThematicBreak") {
return -1;
}
- // 0 正常;1 折叠
- let fold = "0";
- if (nodeElement.getAttribute("fold") === "1") {
+ let hasFold = nodeElement.getAttribute("fold") === "1";
+ if (hasFold) {
if (typeof isOpen === "boolean" && !isOpen) {
return -1;
}
@@ -1885,7 +1884,6 @@ export const setFold = (protyle: IProtyle, nodeElement: Element, isOpen?: boolea
if (typeof isOpen === "boolean" && isOpen) {
return -1;
}
- fold = "1";
nodeElement.setAttribute("fold", "1");
// 光标在子列表中,再次 focus 段尾的时候不会变 https://ld246.com/article/1647099132461
if (getSelection().rangeCount > 0) {
@@ -1909,7 +1907,7 @@ export const setFold = (protyle: IProtyle, nodeElement: Element, isOpen?: boolea
}
const id = nodeElement.getAttribute("data-node-id");
if (nodeElement.getAttribute("data-type") === "NodeHeading") {
- if (fold === "0") {
+ if (hasFold) {
nodeElement.insertAdjacentHTML("beforeend", '<div spin="1" style="text-align: center"><img width="24px" src="/stage/loading-pure.svg"></div>');
transaction(protyle, [{
action: "unfoldHeading",
@@ -1933,14 +1931,14 @@ export const setFold = (protyle: IProtyle, nodeElement: Element, isOpen?: boolea
transaction(protyle, [{
action: "setAttrs",
id,
- data: JSON.stringify({fold})
+ data: JSON.stringify({fold: hasFold ? "" : "1"})
}], [{
action: "setAttrs",
id,
- data: JSON.stringify({fold: fold === "0" ? "1" : "0"})
+ data: JSON.stringify({fold: hasFold ? "1" : ""})
}]);
}
// 折叠后,防止滚动条滚动后调用 get 请求 https://github.com/siyuan-note/siyuan/issues/2248
preventScroll(protyle);
- return fold;
+ return !hasFold ? 1 : 0;
};
diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.ts
index f97b4d4786..83a2f96f72 100644
--- a/app/src/protyle/gutter/index.ts
+++ b/app/src/protyle/gutter/index.ts
@@ -178,12 +178,12 @@ export class Gutter {
doOperations.push({
action: "setAttrs",
id: listId,
- data: JSON.stringify({fold: hasFold ? "0" : "1"})
+ data: JSON.stringify({fold: hasFold ? "" : "1"})
});
undoOperations.push({
action: "setAttrs",
id: listId,
- data: JSON.stringify({fold: hasFold ? "1" : "0"})
+ data: JSON.stringify({fold: hasFold ? "1" : ""})
});
}
});
@@ -193,9 +193,9 @@ export class Gutter {
buttonElement.removeAttribute("disabled");
} else {
const foldStatus = setFold(protyle, foldElement);
- if (foldStatus === "1") {
+ if (foldStatus === 1) {
(buttonElement.firstElementChild as HTMLElement).style.transform = "";
- } else if (foldStatus === "0") {
+ } else if (foldStatus === 0) {
(buttonElement.firstElementChild as HTMLElement).style.transform = "rotate(90deg)";
}
}
@@ -297,12 +297,12 @@ export class Gutter {
doOperations.push({
action: "setAttrs",
id: listId,
- data: JSON.stringify({fold: hasFold ? "0" : "1"})
+ data: JSON.stringify({fold: hasFold ? "" : "1"})
});
undoOperations.push({
action: "setAttrs",
id: listId,
- data: JSON.stringify({fold: hasFold ? "1" : "0"})
+ data: JSON.stringify({fold: hasFold ? "1" : ""})
});
}
});
diff --git a/kernel/api/block_op.go b/kernel/api/block_op.go
index fa7515b4c1..0839d21293 100644
--- a/kernel/api/block_op.go
+++ b/kernel/api/block_op.go
@@ -125,7 +125,7 @@ func unfoldBlock(c *gin.Context) {
},
}
} else {
- data, _ := gulu.JSON.MarshalJSON(map[string]interface{}{"unfold": "1"})
+ data, _ := gulu.JSON.MarshalJSON(map[string]interface{}{"fold": ""})
transactions = []*model.Transaction{
{
DoOperations: []*model.Operation{