🎨 Improve block collapse and expansion operations (#10717)

This commit is contained in:
Yingyi / 颖逸 2024-03-24 22:16:49 +08:00 committed by GitHub
parent 6d833429c9
commit e922c402c8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 15 deletions

View file

@ -1870,9 +1870,8 @@ export const setFold = (protyle: IProtyle, nodeElement: Element, isOpen?: boolea
if (nodeElement.getAttribute("data-type") === "NodeThematicBreak") { if (nodeElement.getAttribute("data-type") === "NodeThematicBreak") {
return -1; return -1;
} }
// 0 正常1 折叠 let hasFold = nodeElement.getAttribute("fold") === "1";
let fold = "0"; if (hasFold) {
if (nodeElement.getAttribute("fold") === "1") {
if (typeof isOpen === "boolean" && !isOpen) { if (typeof isOpen === "boolean" && !isOpen) {
return -1; return -1;
} }
@ -1885,7 +1884,6 @@ export const setFold = (protyle: IProtyle, nodeElement: Element, isOpen?: boolea
if (typeof isOpen === "boolean" && isOpen) { if (typeof isOpen === "boolean" && isOpen) {
return -1; return -1;
} }
fold = "1";
nodeElement.setAttribute("fold", "1"); nodeElement.setAttribute("fold", "1");
// 光标在子列表中,再次 focus 段尾的时候不会变 https://ld246.com/article/1647099132461 // 光标在子列表中,再次 focus 段尾的时候不会变 https://ld246.com/article/1647099132461
if (getSelection().rangeCount > 0) { if (getSelection().rangeCount > 0) {
@ -1909,7 +1907,7 @@ export const setFold = (protyle: IProtyle, nodeElement: Element, isOpen?: boolea
} }
const id = nodeElement.getAttribute("data-node-id"); const id = nodeElement.getAttribute("data-node-id");
if (nodeElement.getAttribute("data-type") === "NodeHeading") { 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>'); nodeElement.insertAdjacentHTML("beforeend", '<div spin="1" style="text-align: center"><img width="24px" src="/stage/loading-pure.svg"></div>');
transaction(protyle, [{ transaction(protyle, [{
action: "unfoldHeading", action: "unfoldHeading",
@ -1933,14 +1931,14 @@ export const setFold = (protyle: IProtyle, nodeElement: Element, isOpen?: boolea
transaction(protyle, [{ transaction(protyle, [{
action: "setAttrs", action: "setAttrs",
id, id,
data: JSON.stringify({fold}) data: JSON.stringify({fold: hasFold ? "" : "1"})
}], [{ }], [{
action: "setAttrs", action: "setAttrs",
id, id,
data: JSON.stringify({fold: fold === "0" ? "1" : "0"}) data: JSON.stringify({fold: hasFold ? "1" : ""})
}]); }]);
} }
// 折叠后,防止滚动条滚动后调用 get 请求 https://github.com/siyuan-note/siyuan/issues/2248 // 折叠后,防止滚动条滚动后调用 get 请求 https://github.com/siyuan-note/siyuan/issues/2248
preventScroll(protyle); preventScroll(protyle);
return fold; return !hasFold ? 1 : 0;
}; };

View file

@ -178,12 +178,12 @@ export class Gutter {
doOperations.push({ doOperations.push({
action: "setAttrs", action: "setAttrs",
id: listId, id: listId,
data: JSON.stringify({fold: hasFold ? "0" : "1"}) data: JSON.stringify({fold: hasFold ? "" : "1"})
}); });
undoOperations.push({ undoOperations.push({
action: "setAttrs", action: "setAttrs",
id: listId, 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"); buttonElement.removeAttribute("disabled");
} else { } else {
const foldStatus = setFold(protyle, foldElement); const foldStatus = setFold(protyle, foldElement);
if (foldStatus === "1") { if (foldStatus === 1) {
(buttonElement.firstElementChild as HTMLElement).style.transform = ""; (buttonElement.firstElementChild as HTMLElement).style.transform = "";
} else if (foldStatus === "0") { } else if (foldStatus === 0) {
(buttonElement.firstElementChild as HTMLElement).style.transform = "rotate(90deg)"; (buttonElement.firstElementChild as HTMLElement).style.transform = "rotate(90deg)";
} }
} }
@ -297,12 +297,12 @@ export class Gutter {
doOperations.push({ doOperations.push({
action: "setAttrs", action: "setAttrs",
id: listId, id: listId,
data: JSON.stringify({fold: hasFold ? "0" : "1"}) data: JSON.stringify({fold: hasFold ? "" : "1"})
}); });
undoOperations.push({ undoOperations.push({
action: "setAttrs", action: "setAttrs",
id: listId, id: listId,
data: JSON.stringify({fold: hasFold ? "1" : "0"}) data: JSON.stringify({fold: hasFold ? "1" : ""})
}); });
} }
}); });

View file

@ -125,7 +125,7 @@ func unfoldBlock(c *gin.Context) {
}, },
} }
} else { } else {
data, _ := gulu.JSON.MarshalJSON(map[string]interface{}{"unfold": "1"}) data, _ := gulu.JSON.MarshalJSON(map[string]interface{}{"fold": ""})
transactions = []*model.Transaction{ transactions = []*model.Transaction{
{ {
DoOperations: []*model.Operation{ DoOperations: []*model.Operation{