Skip to content

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

:bug: Prevent flicker when expanding empty headings https://github.com/siyuan-note/siyuan/issues/19587

Danielea340631e90d
diff --git a/app/src/card/openCard.ts b/app/src/card/openCard.ts
index be02fae323..29824be51c 100644
--- a/app/src/card/openCard.ts
+++ b/app/src/card/openCard.ts
@@ -251,7 +251,7 @@ const revealFlashcardAnswer = (protyle: IProtyle, callback: () => void) => {
state: revealState,
generation,
unfold: cardElement ? (done) => {
- const foldData = setFold(protyle, cardElement, true, false, true, true);
+ const foldData = setFold(protyle, cardElement, true, false, true);
if (!foldData.doOperations?.length) {
done();
return;
diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts
index 99ef83ea15..975454bb70 100644
--- a/app/src/menus/protyle.ts
+++ b/app/src/menus/protyle.ts
@@ -2772,7 +2772,7 @@ export const setFoldById = (data: {
}, protyle: IProtyle) => {
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${data.id}"]`)).find((item: Element) => {
if (!isInEmbedBlock(item)) {
- const operations = setFold(protyle, item, true, false, true, true);
+ const operations = setFold(protyle, item, true, false, true);
if (hasViewFoldContext(protyle)) {
const occurrenceID = getViewFoldOccurrenceID(protyle, item);
void setViewFoldTransient(protyle, item, false, undefined, true).then(() => {
diff --git a/app/src/protyle/hint/index.ts b/app/src/protyle/hint/index.ts
index a31bdadeb8..9d39feaac4 100644
--- a/app/src/protyle/hint/index.ts
+++ b/app/src/protyle/hint/index.ts
@@ -1179,7 +1179,7 @@ ${genHintItemHTML(item)}
let foldData;
if (nodeElement.getAttribute("data-type") === "NodeHeading" &&
nodeElement.getAttribute("fold") === "1") {
- foldData = setFold(protyle, nodeElement, true, false, false, true);
+ foldData = setFold(protyle, nodeElement, true, false, true);
}
nodeElement.insertAdjacentHTML("afterend", newHTML);
const newId = newHTML.substr(newHTML.indexOf('data-node-id="') + 14, 22);
diff --git a/app/src/protyle/util/blockFold.ts b/app/src/protyle/util/blockFold.ts
index 945652b000..391e40e027 100644
--- a/app/src/protyle/util/blockFold.ts
+++ b/app/src/protyle/util/blockFold.ts
@@ -52,7 +52,7 @@ const getEmptyFoldResult = () => ({
});
export const setFold = (protyle: IProtyle, nodeElement: Element, isOpen?: boolean,
- isRemove?: boolean, addLoading = true, getOperations = false,
+ isRemove?: boolean, getOperations = false,
persistViewState = !getOperations) => {
if (nodeElement.getAttribute("data-type") === "NodeListItem" && nodeElement.childElementCount < 4 &&
// 该情况需要强制展开 https://github.com/siyuan-note/siyuan/issues/12327
@@ -127,9 +127,6 @@ export const setFold = (protyle: IProtyle, nodeElement: Element, isOpen?: boolea
const undoOperations: IOperation[] = [];
if (nodeElement.getAttribute("data-type") === "NodeHeading") {
if (hasFold) {
- if (addLoading) {
- nodeElement.insertAdjacentHTML("beforeend", '<div spin="1" style="text-align: center"><img width="24px" height="24px" src="/stage/loading-pure.svg"></div>');
- }
doOperations.push({
action: "unfoldHeading",
id,
diff --git a/app/src/protyle/util/editorCommonEvent.ts b/app/src/protyle/util/editorCommonEvent.ts
index 4030283b70..9fc02e7c34 100644
--- a/app/src/protyle/util/editorCommonEvent.ts
+++ b/app/src/protyle/util/editorCommonEvent.ts
@@ -997,7 +997,7 @@ const dragSame = async (protyle: IProtyle, sourceElements: Element[], targetElem
});
}
unfoldHeadingElements.forEach(item => {
- const foldData = setFold(protyle, item, true, false, false, true);
+ const foldData = setFold(protyle, item, true, false, true);
if (!foldData.doOperations?.length) {
return;
}
diff --git a/app/src/protyle/util/insertHTML.ts b/app/src/protyle/util/insertHTML.ts
index 5b973f0fee..3bd65781c4 100644
--- a/app/src/protyle/util/insertHTML.ts
+++ b/app/src/protyle/util/insertHTML.ts
@@ -1504,7 +1504,7 @@ export const insertHTML = (html: string, protyle: IProtyle, isBlock = false,
fetchPost("/api/block/getHeadingChildrenIDs", {id: blockElement.getAttribute("data-node-id")}, (response) => {
const childrenIDs: string[] = response.data;
const previousId = (childrenIDs && childrenIDs.length > 0) ? childrenIDs[childrenIDs.length - 1] : blockElement.getAttribute("data-node-id");
- foldData = setFold(protyle, blockElement, true, false, false, true);
+ foldData = setFold(protyle, blockElement, true, false, true);
if (foldData.doOperations.length > 0) {
foldData.doOperations[0].context = {
focusId: lastElement?.getAttribute("data-node-id"),
diff --git a/app/src/protyle/wysiwyg/input.ts b/app/src/protyle/wysiwyg/input.ts
index 36f97e7030..43acfbffa8 100644
--- a/app/src/protyle/wysiwyg/input.ts
+++ b/app/src/protyle/wysiwyg/input.ts
@@ -445,7 +445,7 @@ export const input = async (protyle: IProtyle, blockElement: HTMLElement, range:
) {
if (blockElement.getAttribute("data-type") === "NodeHeading" && blockElement.getAttribute("fold") === "1" &&
tempElement.content.firstElementChild.getAttribute("data-subtype") !== blockElement.dataset.subtype) {
- setFold(protyle, blockElement, undefined, undefined, false, false, false);
+ setFold(protyle, blockElement, undefined, undefined, false, false);
html = html.replace(' fold="1"', "");
protyle.wysiwyg.lastHTMLs[id] = blockElement.outerHTML;
}
diff --git a/app/src/protyle/wysiwyg/list.ts b/app/src/protyle/wysiwyg/list.ts
index e17eb90fa3..b178e00b63 100644
--- a/app/src/protyle/wysiwyg/list.ts
+++ b/app/src/protyle/wysiwyg/list.ts
@@ -43,7 +43,7 @@ const getLastChildBlock = (element: Element) => {
const unfoldElements = (protyle: IProtyle, elements: Element[]) => {
elements.forEach(item => {
if (item.getAttribute("fold") === "1") {
- setFold(protyle, item, true, false, false, false, false);
+ setFold(protyle, item, true, false, false, false);
}
});
};
@@ -646,7 +646,7 @@ export const insertEmptyChildList = (protyle: IProtyle, previousElement: HTMLEle
if (item.getAttribute("fold") !== "1") {
return;
}
- const foldData = setFold(protyle, item, true, false, false, true);
+ const foldData = setFold(protyle, item, true, false, true);
if (foldData?.doOperations?.length > 0) {
doOperations.push(...foldData.doOperations);
undoOperations.push(...foldData.undoOperations);
@@ -906,7 +906,7 @@ export const listIndent = async (protyle: IProtyle, liItemElements: Element[], r
});
});
}
- const foldOperations = setFold(protyle, foldElement, true, false, false, true);
+ const foldOperations = setFold(protyle, foldElement, true, false, true);
doOperations.push(...foldOperations.doOperations);
undoOperations.push(...foldOperations.undoOperations);
if (focusedParentListElement) {
diff --git a/app/src/protyle/wysiwyg/remove.ts b/app/src/protyle/wysiwyg/remove.ts
index 64f689641f..73ad174fa6 100644
--- a/app/src/protyle/wysiwyg/remove.ts
+++ b/app/src/protyle/wysiwyg/remove.ts
@@ -1214,7 +1214,7 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rang
}
tabsRemoval.normalize();
Object.keys(unfoldData).forEach(item => {
- const foldOperations = setFold(protyle, unfoldData[item].element, true, false, false, true);
+ const foldOperations = setFold(protyle, unfoldData[item].element, true, false, true);
deletes.push(...foldOperations.doOperations);
inserts.splice(0, 0, ...foldOperations.undoOperations);
});
@@ -1551,11 +1551,11 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rang
const previousBlockElement = getPreviousBlockSibling(blockElement);
if (previousBlockElement?.getAttribute("data-type") === "NodeHeading" &&
previousBlockElement.getAttribute("fold") === "1") {
- setFold(protyle, previousBlockElement, true, false, false, false, false);
+ setFold(protyle, previousBlockElement, true, false, false, false);
}
if (blockType === "NodeHeading" &&
blockElement.getAttribute("fold") === "1") {
- setFold(protyle, blockElement, true, false, false, false, false);
+ setFold(protyle, blockElement, true, false, false, false);
}
turnsIntoTransaction({
protyle: protyle,
@@ -1788,7 +1788,7 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rang
// https://github.com/siyuan-note/siyuan/issues/12327
if (removeParentElement.classList.contains("li") && removeParentElement.childElementCount === 4 &&
removeParentElement.getAttribute("fold") === "1") {
- const foldOperations = setFold(protyle, removeParentElement, true, false, false, true);
+ const foldOperations = setFold(protyle, removeParentElement, true, false, true);
doOperations.push(...foldOperations.doOperations);
undoOperations.splice(0, 0, ...foldOperations.undoOperations);
}
@@ -2182,7 +2182,7 @@ const removeLi = async (protyle: IProtyle, blockElement: Element, range: Range,
}
if (foldElement) {
- const foldOperations = setFold(protyle, foldElement, true, false, false, true);
+ const foldOperations = setFold(protyle, foldElement, true, false, true);
doOperations.push(...foldOperations.doOperations);
undoOperations.push(...foldOperations.undoOperations);
if (foldElement.parentElement.getAttribute("data-subtype") === "o") {
diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.ts
index eea4b26408..f362cd2064 100644
--- a/app/src/protyle/wysiwyg/transaction.ts
+++ b/app/src/protyle/wysiwyg/transaction.ts
@@ -1664,7 +1664,7 @@ export const insertEmptyBlockquote = (protyle: IProtyle, previousElement: HTMLEl
let foldData;
if (previousElement.getAttribute("data-type") === "NodeHeading" && previousElement.getAttribute("fold") === "1") {
- foldData = setFold(protyle, previousElement, true, false, false, true);
+ foldData = setFold(protyle, previousElement, true, false, true);
}
const id = blockquoteElement.getAttribute("data-node-id");
@@ -1899,7 +1899,7 @@ export const turnsIntoTransaction = (options: {
let foldData;
if (item.getAttribute("data-type") === "NodeHeading" && item.getAttribute("fold") === "1" &&
tempElement.content.firstElementChild.getAttribute("data-subtype") !== item.dataset.subtype) {
- foldData = setFold(options.protyle, item, undefined, undefined, false, true);
+ foldData = setFold(options.protyle, item, undefined, undefined, true);
newHTML = newHTML.replace(' fold="1"', "");
}
if (foldData && foldData.doOperations?.length > 0) {
@@ -2423,7 +2423,7 @@ const processFold = (operation: IOperation, protyle: IProtyle) => {
return;
}
item.removeAttribute("fold");
- if (!item.lastElementChild.classList.contains("protyle-attr")) {
+ if (item.lastElementChild?.getAttribute("spin") === "1") {
item.lastElementChild.remove();
}
removeUnfoldRepeatBlock(visibleRetData, protyle);