Vanessa 2024-09-06 16:58:25 +08:00
parent c33401ed7c
commit 1d8ba5b225
5 changed files with 47 additions and 5 deletions

View file

@ -2,7 +2,9 @@ import {Constants} from "../constants";
import {fetchPost} from "../util/fetch";
/// #if !MOBILE
import {exportLayout} from "../layout/util";
import {getAllModels} from "../layout/getAll";
/// #endif
import {getAllEditor} from "../layout/getAll";
/// #if !BROWSER
import {ipcRenderer} from "electron";
/// #endif
@ -14,7 +16,6 @@ import {escapeHtml} from "../util/escape";
import {getWorkspaceName} from "../util/noRelyPCFunction";
import {needSubscribe} from "../util/needSubscribe";
import {redirectToCheckAuth, setNoteBook} from "../util/pathName";
import {getAllEditor, getAllModels} from "../layout/getAll";
import {reloadProtyle} from "../protyle/util/reload";
import {Tab} from "../layout/Tab";
import {setEmpty} from "../mobile/util/setEmpty";
@ -159,6 +160,21 @@ export const setRefDynamicText = (data: {
})
}
export const setDefRefCount = (data: {
"blockID": string,
"defBlockID": string,
"refText": string,
"rootID": string
}) => {
getAllEditor().forEach(item => {
// 不能对比 rootId否则潜入块中的锚文本无法更新
const refElement = item.protyle.wysiwyg.element.querySelector(`[data-node-id="${data.blockID}"] span[data-type="block-ref"][data-subtype="d"][data-id="${data.defBlockID}"]`);
if (refElement) {
refElement.innerHTML = data.refText;
}
})
}
export const lockScreen = (app: App) => {
if (window.siyuan.config.readonly) {
return;

View file

@ -17,7 +17,7 @@ import {
progressBackgroundTask,
progressLoading,
progressStatus,
reloadSync, setRefDynamicText,
reloadSync, setDefRefCount, setRefDynamicText,
setTitle,
transactionError
} from "./dialog/processSystem";
@ -61,6 +61,9 @@ export class App {
});
if (data) {
switch (data.cmd) {
case "setDefRefCount":
setDefRefCount(data.data);
break;
case "setRefDynamicText":
setRefDynamicText(data.data);
break;

View file

@ -1,3 +1,4 @@
/// #if !MOBILE
import {Layout} from "./index";
import {Tab} from "./Tab";
import {Editor} from "../editor";
@ -12,10 +13,19 @@ import {Tag} from "./dock/Tag";
import {Custom} from "./dock/Custom";
import {Protyle} from "../protyle";
import {Wnd} from "./Wnd";
/// #endif
export const getAllEditor = () => {
const models = getAllModels();
const editors: Protyle[] = [];
/// #if MOBILE
if (window.siyuan.mobile.editor) {
editors.push(window.siyuan.mobile.editor);
}
if (window.siyuan.mobile.popEditor) {
editors.push(window.siyuan.mobile.popEditor);
}
/// #else
const models = getAllModels();
models.editor.forEach(item => {
editors.push(item.editor);
});
@ -45,6 +55,7 @@ export const getAllEditor = () => {
editors.push(editorItem);
});
});
/// #endif
return editors;
};

View file

@ -3,7 +3,7 @@ import {
processSync,
progressLoading,
progressStatus,
reloadSync,
reloadSync, setDefRefCount, setRefDynamicText,
transactionError
} from "../../dialog/processSystem";
import {Constants} from "../../constants";
@ -14,6 +14,12 @@ import {reloadEmoji} from "../../emoji";
export const onMessage = (app: App, data: IWebSocketData) => {
if (data) {
switch (data.cmd) {
case "setDefRefCount":
setDefRefCount(data.data);
break;
case "setRefDynamicText":
setRefDynamicText(data.data);
break;
case "reloadPlugin":
reloadPlugin(app, data.data);
break;

View file

@ -11,7 +11,7 @@ import {openFileById} from "../editor/util";
import {
processSync, progressBackgroundTask,
progressLoading,
progressStatus, reloadSync,
progressStatus, reloadSync, setDefRefCount, setRefDynamicText,
setTitle,
transactionError
} from "../dialog/processSystem";
@ -50,6 +50,12 @@ class App {
});
if (data) {
switch (data.cmd) {
case "setDefRefCount":
setDefRefCount(data.data);
break;
case "setRefDynamicText":
setRefDynamicText(data.data);
break;
case "reloadPlugin":
reloadPlugin(this, data.data);
break;