From 2cec76fcc5996e657e9018e51ea7485b4a43cd2a Mon Sep 17 00:00:00 2001 From: Vanessa Date: Tue, 23 Jan 2024 13:08:49 +0800 Subject: [PATCH] :art: fix https://github.com/siyuan-note/siyuan/issues/10230 --- app/src/card/openCard.ts | 40 +++++++++++++++++++++------------ app/src/card/viewCards.ts | 22 +++++++++++------- app/src/mobile/editor.ts | 9 +++++++- app/src/protyle/util/onGet.ts | 12 ++++++---- app/src/search/util.ts | 42 ++++++++++++++++++++--------------- 5 files changed, 80 insertions(+), 45 deletions(-) diff --git a/app/src/card/openCard.ts b/app/src/card/openCard.ts index 7f637acfc..ffa88dbc5 100644 --- a/app/src/card/openCard.ts +++ b/app/src/card/openCard.ts @@ -158,15 +158,21 @@ export const bindCardEvent = async (options: { window.siyuan.mobile.popEditor = editor; } if (options.cardsData.cards.length > 0) { - fetchPost("/api/filetree/getDoc", { + fetchPost("/api/block/getDocInfo", { id: options.cardsData.cards[index].blockID, - mode: 0, - size: Constants.SIZE_GET_MAX }, (response) => { - onGet({ - data: response, - protyle: editor.protyle, - action: response.data.rootID === response.data.id ? [Constants.CB_GET_HTML] : [Constants.CB_GET_ALL, Constants.CB_GET_HTML], + editor.protyle.wysiwyg.renderCustom(response.data.ial); + fetchPost("/api/filetree/getDoc", { + id: options.cardsData.cards[index].blockID, + mode: 0, + size: Constants.SIZE_GET_MAX + }, (response) => { + onGet({ + updateReadonly: true, + data: response, + protyle: editor.protyle, + action: response.data.rootID === response.data.id ? [Constants.CB_GET_HTML] : [Constants.CB_GET_ALL, Constants.CB_GET_HTML], + }); }); }); } @@ -531,15 +537,21 @@ const nextCard = (options: { } else { options.actionElements[0].firstElementChild.removeAttribute("disabled"); } - fetchPost("/api/filetree/getDoc", { + fetchPost("/api/block/getDocInfo", { id: options.blocks[options.index].blockID, - mode: 0, - size: Constants.SIZE_GET_MAX }, (response) => { - onGet({ - data: response, - protyle: options.editor.protyle, - action: response.data.rootID === response.data.id ? [Constants.CB_GET_HTML] : [Constants.CB_GET_ALL, Constants.CB_GET_HTML], + options.editor.protyle.wysiwyg.renderCustom(response.data.ial); + fetchPost("/api/filetree/getDoc", { + id: options.blocks[options.index].blockID, + mode: 0, + size: Constants.SIZE_GET_MAX + }, (response) => { + onGet({ + updateReadonly: true, + data: response, + protyle: options.editor.protyle, + action: response.data.rootID === response.data.id ? [Constants.CB_GET_HTML] : [Constants.CB_GET_ALL, Constants.CB_GET_HTML], + }); }); }); }; diff --git a/app/src/card/viewCards.ts b/app/src/card/viewCards.ts index 9dfdf7584..712758f79 100644 --- a/app/src/card/viewCards.ts +++ b/app/src/card/viewCards.ts @@ -288,15 +288,21 @@ const getArticle = (edit: Protyle, id: string) => { edit.protyle.element.nextElementSibling.classList.add("fn__none"); edit.protyle.scroll.lastScrollTop = 0; addLoading(edit.protyle); - fetchPost("/api/filetree/getDoc", { + fetchPost("/api/block/getDocInfo", { id, - mode: 0, - size: Constants.SIZE_GET_MAX, - }, getResponse => { - onGet({ - data: getResponse, - protyle: edit.protyle, - action: getResponse.data.rootID === getResponse.data.id ? [Constants.CB_GET_HTML] : [Constants.CB_GET_ALL, Constants.CB_GET_HTML], + }, (response) => { + edit.protyle.wysiwyg.renderCustom(response.data.ial); + fetchPost("/api/filetree/getDoc", { + id, + mode: 0, + size: Constants.SIZE_GET_MAX, + }, getResponse => { + onGet({ + updateReadonly: true, + data: getResponse, + protyle: edit.protyle, + action: getResponse.data.rootID === getResponse.data.id ? [Constants.CB_GET_HTML] : [Constants.CB_GET_ALL, Constants.CB_GET_HTML], + }); }); }); }; diff --git a/app/src/mobile/editor.ts b/app/src/mobile/editor.ts index 161a0b99b..2524a6a3d 100644 --- a/app/src/mobile/editor.ts +++ b/app/src/mobile/editor.ts @@ -65,6 +65,9 @@ export const openMobileFileById = (app: App, id: string, action = [Constants.CB_ if (window.siyuan.mobile.editor) { pushBack(); addLoading(window.siyuan.mobile.editor.protyle); + if (window.siyuan.mobile.editor.protyle.block.rootID !== data.data.rootID) { + window.siyuan.mobile.editor.protyle.wysiwyg.element.innerHTML = ""; + } if (action.includes(Constants.CB_GET_SCROLL) && window.siyuan.storage[Constants.LOCAL_FILEPOSITION][data.data.rootID]) { getDocByScroll({ protyle: window.siyuan.mobile.editor.protyle, @@ -77,7 +80,11 @@ export const openMobileFileById = (app: App, id: string, action = [Constants.CB_ size: action.includes(Constants.CB_GET_ALL) ? Constants.SIZE_GET_MAX : window.siyuan.config.editor.dynamicLoadBlocks, mode: action.includes(Constants.CB_GET_CONTEXT) ? 3 : 0, }, getResponse => { - onGet({data: getResponse, protyle: window.siyuan.mobile.editor.protyle, action}); + onGet({ + data: getResponse, + protyle: window.siyuan.mobile.editor.protyle, + action + }); }); } window.siyuan.mobile.editor.protyle.undo.clear(); diff --git a/app/src/protyle/util/onGet.ts b/app/src/protyle/util/onGet.ts index 082ffd91b..14177982a 100644 --- a/app/src/protyle/util/onGet.ts +++ b/app/src/protyle/util/onGet.ts @@ -24,6 +24,7 @@ export const onGet = (options: { protyle: IProtyle, action?: string[], scrollAttr?: IScrollAttr + updateReadonly?: boolean afterCB?: () => void }) => { if (!options.action) { @@ -79,6 +80,7 @@ export const onGet = (options: { expand: options.data.data.isBacklinkExpand, action: options.action, scrollAttr: options.scrollAttr, + updateReadonly: options.updateReadonly, isSyncing: options.data.data.isSyncing, afterCB: options.afterCB, }, options.protyle); @@ -104,6 +106,7 @@ export const onGet = (options: { expand: options.data.data.isBacklinkExpand, action: options.action, scrollAttr: options.scrollAttr, + updateReadonly: options.updateReadonly, isSyncing: options.data.data.isSyncing, afterCB: options.afterCB, }, options.protyle); @@ -116,6 +119,7 @@ const setHTML = (options: { action?: string[], isSyncing: boolean, expand: boolean, + updateReadonly?: boolean, scrollAttr?: IScrollAttr afterCB?: () => void }, protyle: IProtyle) => { @@ -124,7 +128,7 @@ const setHTML = (options: { } protyle.block.showAll = options.action.includes(Constants.CB_GET_ALL); const REMOVED_OVER_HEIGHT = protyle.contentElement.clientHeight * 8; - const isUpdate = protyle.wysiwyg.element.innerHTML !== ""; + const updateReadonly = typeof options.updateReadonly === "undefined" ? protyle.wysiwyg.element.innerHTML === "" : options.updateReadonly; if (options.action.includes(Constants.CB_GET_APPEND)) { // 动态加载移除 if (!protyle.wysiwyg.element.querySelector(".protyle-wysiwyg--select") && !protyle.scroll.keepLazyLoad && protyle.contentElement.scrollHeight > REMOVED_OVER_HEIGHT) { @@ -199,7 +203,7 @@ const setHTML = (options: { protyle.breadcrumb.element.nextElementSibling.textContent = ""; } protyle.element.removeAttribute("disabled-forever"); - setReadonlyByConfig(protyle, isUpdate); + setReadonlyByConfig(protyle, updateReadonly); } focusElementById(protyle, options.action, options.scrollAttr); @@ -432,9 +436,9 @@ const focusElementById = (protyle: IProtyle, action: string[], scrollAttr?: IScr } }; -export const setReadonlyByConfig = (protyle: IProtyle, isUpdate: boolean) => { +export const setReadonlyByConfig = (protyle: IProtyle, updateReadonly: boolean) => { let readOnly = window.siyuan.config.readonly ? "true" : "false"; - if (isUpdate) { + if (!updateReadonly) { readOnly = protyle.disabled ? "true" : "false"; } else if (readOnly === "false") { readOnly = window.siyuan.config.editor.readOnly ? "true" : "false"; diff --git a/app/src/search/util.ts b/app/src/search/util.ts index 7b98a4620..3c1ff9a1d 100644 --- a/app/src/search/util.ts +++ b/app/src/search/util.ts @@ -1108,26 +1108,32 @@ export const getArticle = (options: { checkFold(options.id, (zoomIn) => { options.edit.protyle.scroll.lastScrollTop = 0; addLoading(options.edit.protyle); - fetchPost("/api/filetree/getDoc", { + fetchPost("/api/block/getDocInfo", { id: options.id, - query: options.value, - queryMethod: options.config.method, - queryTypes: options.config.types, - mode: zoomIn ? 0 : 3, - size: zoomIn ? Constants.SIZE_GET_MAX : window.siyuan.config.editor.dynamicLoadBlocks, - zoom: zoomIn, - }, getResponse => { - onGet({ - data: getResponse, - protyle: options.edit.protyle, - action: zoomIn ? [Constants.CB_GET_ALL, Constants.CB_GET_HTML] : [Constants.CB_GET_HL, Constants.CB_GET_HTML], + }, (response) => { + options.edit.protyle.wysiwyg.renderCustom(response.data.ial); + fetchPost("/api/filetree/getDoc", { + id: options.id, + query: options.value, + queryMethod: options.config.method, + queryTypes: options.config.types, + mode: zoomIn ? 0 : 3, + size: zoomIn ? Constants.SIZE_GET_MAX : window.siyuan.config.editor.dynamicLoadBlocks, + zoom: zoomIn, + }, getResponse => { + onGet({ + updateReadonly: true, + data: getResponse, + protyle: options.edit.protyle, + action: zoomIn ? [Constants.CB_GET_ALL, Constants.CB_GET_HTML] : [Constants.CB_GET_HL, Constants.CB_GET_HTML], + }); + const matchElement = options.edit.protyle.wysiwyg.element.querySelector(`div[data-node-id="${options.id}"] span[data-type~="search-mark"]`); + if (matchElement) { + matchElement.classList.add("search-mark--hl"); + const contentRect = options.edit.protyle.contentElement.getBoundingClientRect(); + options.edit.protyle.contentElement.scrollTop = options.edit.protyle.contentElement.scrollTop + matchElement.getBoundingClientRect().top - contentRect.top - contentRect.height / 2; + } }); - const matchElement = options.edit.protyle.wysiwyg.element.querySelector(`div[data-node-id="${options.id}"] span[data-type~="search-mark"]`); - if (matchElement) { - matchElement.classList.add("search-mark--hl"); - const contentRect = options.edit.protyle.contentElement.getBoundingClientRect(); - options.edit.protyle.contentElement.scrollTop = options.edit.protyle.contentElement.scrollTop + matchElement.getBoundingClientRect().top - contentRect.top - contentRect.height / 2; - } }); }); };