An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Reuse the select-all tip notification while loading the document
Jeffrey Chen6e28da5af1c3
diff --git a/app/src/dialog/message.test.ts b/app/src/dialog/message.test.tsindex 20f54cd1c4..e9ac8bbd1a 100644--- a/app/src/dialog/message.test.ts+++ b/app/src/dialog/message.test.ts@@ -63,6 +63,10 @@ const cases = async (source: string) => {api.showMessage(notification, -1, "info", "unrelated");button().click();check.equal(requests, 2, "only the update notification can invoke the download action");+ check.equal(api.showMessage("Loading...", -1, "info", "select-all-tip"), "select-all-tip",+ "replacing an existing notification returns its id so callers can hide it");+ check.equal(message.querySelectorAll('[data-id="select-all-tip"]').length, 1,+ "replacing an existing notification reuses its element");return "update-message-ok";};diff --git a/app/src/dialog/message.ts b/app/src/dialog/message.tsindex fd067e31db..419808163b 100644--- a/app/src/dialog/message.ts+++ b/app/src/dialog/message.ts@@ -108,7 +108,8 @@ data-message-id="${safeMessageId || ""}">${safeMessage}</div>`);}, timeout);existElement.setAttribute("data-timeoutid", timeoutId.toString());}- return;+ // 复用已有通知时同样返回 id,调用方才能按 id 关闭它+ return id;}let messageHTML = `<div data-id="${id}" class="b3-snackbar--hide b3-snackbar${type === "error" ? " b3-snackbar--error" : ""}"><div data-type="textMenu" class="b3-snackbar__content${timeout === 0 ? " b3-snackbar__content--close" : ""}">${messageVersion}</div>`;if (timeout === 0) {diff --git a/app/src/protyle/scroll/index.ts b/app/src/protyle/scroll/index.tsindex 9d0f55028e..e03ea73985 100644--- a/app/src/protyle/scroll/index.ts+++ b/app/src/protyle/scroll/index.ts@@ -230,7 +230,8 @@ export class Scroll {return true;}- public async loadAll(protyle: IProtyle) {+ // messageId 用于复用调用方已展示的通知,避免新增一条提示把通知列表挤得跳动+ public async loadAll(protyle: IProtyle, options?: { messageId?: string }) {const rootID = protyle.block.rootID;if (this.loadingAll || !rootID || protyle.block.showAll || !protyle.block.scroll) {return false;@@ -238,7 +239,7 @@ export class Scroll {this.loadingAll = true;this.invalidateDynamicLoad(protyle);- const messageID = showMessage(window.siyuan.languages.loading, -1);+ const messageID = showMessage(window.siyuan.languages.loading, -1, "info", options?.messageId);const size = Math.max(window.siyuan.config.editor.dynamicLoadBlocks,protyle.block.blockCount || 0diff --git a/app/src/protyle/util/selectAllTip.ts b/app/src/protyle/util/selectAllTip.tsindex 7be982487e..412fa05b47 100644--- a/app/src/protyle/util/selectAllTip.ts+++ b/app/src/protyle/util/selectAllTip.ts@@ -34,7 +34,7 @@ export const showSelectAllIncompleteTip = (protyle: IProtyle) => {button.disabled = true;try {if (hasUnloadedDocumentBlocks(editorElement, protyle.block.scroll) &&- !await protyle.scroll.loadAll(protyle)) {+ !await protyle.scroll.loadAll(protyle, {messageId: messageID})) {return;}if (!isCurrent()) {diff --git a/app/tests/selectAllTip.test.js b/app/tests/selectAllTip.test.jsindex 5be1835fac..2faaa11aca 100644--- a/app/tests/selectAllTip.test.js+++ b/app/tests/selectAllTip.test.js@@ -71,12 +71,14 @@ const runCases = async sources => {const subElement = document.getElementById("toolbar");let complete;let requests = 0;+ let loadAllOptions;const protyle = {element: document.getElementById("editor"),block: {rootID: "document", parentID: "document", scroll: true},options: {}, wysiwyg: {element},- scroll: {loadAll: () => {+ scroll: {loadAll: (currentProtyle, options) => {requests++;+ loadAllOptions = options;return new Promise((resolve, reject) => complete = (success, error) => {if (error) {reject(new Error("Loading failed"));@@ -103,7 +105,8 @@ const runCases = async sources => {const show = () => showSelectAllIncompleteTip(protyle);const button = () => document.querySelector('#message [data-id="selectAllIncompleteTip"] button');const selected = () => Array.from(element.querySelectorAll(".protyle-wysiwyg--select"), item => item.dataset.nodeId);- return {protyle, element, show, button, selected, complete: (...args) => complete(...args), requests: () => requests};+ return {protyle, element, show, button, selected, complete: (...args) => complete(...args),+ requests: () => requests, loadAllOptions: () => loadAllOptions};};// 重复提示会替换按钮,必须绑定最新按钮,并等待全文成功加载后再选择顶层块。@@ -119,6 +122,8 @@ const runCases = async sources => {f.button().click();f.button().click();check.equal(f.requests(), 1);+ // 加载提示复用本条通知的 id,避免新增通知导致列表位置跳动+ check.deepEqual(f.loadAllOptions(), {messageId: "selectAllIncompleteTip"});check.equal(f.button().disabled, true);check.deepEqual(f.selected(), ["middle", "nested"]);f.complete(true);