Skip to content

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

:art: fix https://github.com/siyuan-note/siyuan/issues/8256

Vanessa6690084caa56
diff --git a/app/src/editor/util.ts b/app/src/editor/util.ts
index fc721bd6e9..98c4d8e551 100644
--- a/app/src/editor/util.ts
+++ b/app/src/editor/util.ts
@@ -506,7 +506,7 @@ export const isCurrentEditor = (blockId: string) => {
return true;
};
-const updateOutline = (models: IModels, protyle: IProtyle, reload = false) => {
+export const updateOutline = (models: IModels, protyle: IProtyle, reload = false) => {
models.outline.find(item => {
if (reload || (item.type === "pin" && (!protyle || item.blockId !== protyle.block?.rootID))) {
let blockId = "";
diff --git a/app/src/layout/dock/Outline.ts b/app/src/layout/dock/Outline.ts
index 6b3d7ca922..8e8156c2d2 100644
--- a/app/src/layout/dock/Outline.ts
+++ b/app/src/layout/dock/Outline.ts
@@ -218,6 +218,9 @@ export class Outline extends Model {
}
public setCurrent(nodeElement: HTMLElement) {
+ if (!nodeElement) {
+ return;
+ }
if (nodeElement.getAttribute("data-type") === "NodeHeading") {
this.setCurrentById(nodeElement.getAttribute("data-node-id"));
} else {
diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts
index 2c615e0c21..03fe5ab525 100644
--- a/app/src/menus/protyle.ts
+++ b/app/src/menus/protyle.ts
@@ -493,7 +493,13 @@ export const zoomOut = (protyle: IProtyle, id: string, focusId?: string, isPushB
}
/// #if !MOBILE
if (protyle.model) {
- updateBacklinkGraph(getAllModels(), protyle);
+ const allModels = getAllModels()
+ allModels.outline.forEach(item => {
+ if (item.blockId === protyle.block.rootID) {
+ item.setCurrent(protyle.wysiwyg.element.querySelector(`[data-node-id="${focusId || id}"]`));
+ }
+ });
+ updateBacklinkGraph(allModels, protyle);
}
/// #endif
if (callback) {
diff --git a/app/src/protyle/breadcrumb/index.ts b/app/src/protyle/breadcrumb/index.ts
index a76f829936..5d5731b5b0 100644
--- a/app/src/protyle/breadcrumb/index.ts
+++ b/app/src/protyle/breadcrumb/index.ts
@@ -16,7 +16,6 @@ import {getEditorRange} from "../util/selection";
import {setPadding} from "../ui/initUI";
/// #if !MOBILE
import {openFileById} from "../../editor/util";
-import {getAllModels} from "../../layout/getAll";
/// #endif
/// #if !BROWSER
import {getCurrentWindow, systemPreferences} from "@electron/remote";
diff --git a/app/src/util/backForward.ts b/app/src/util/backForward.ts
index 802b0dd1b6..87c083a367 100644
--- a/app/src/util/backForward.ts
+++ b/app/src/util/backForward.ts
@@ -13,13 +13,14 @@ import {scrollCenter} from "./highlightById";
import {zoomOut} from "../menus/protyle";
import {showMessage} from "../dialog/message";
import {saveScroll} from "../protyle/scroll/saveScroll";
+import {getAllModels} from "../layout/getAll";
let forwardStack: IBackStack[] = [];
let previousIsBack = false;
const focusStack = async (stack: IBackStack) => {
hideElements(["gutter", "toolbar", "hint", "util", "dialog"], stack.protyle);
- let blockElement: Element;
+ let blockElement: HTMLElement;
if (!document.contains(stack.protyle.element)) {
const response = await fetchSyncPost("/api/block/checkBlockExist", {id: stack.protyle.block.rootID});
if (!response.data) {
@@ -91,7 +92,7 @@ const focusStack = async (stack: IBackStack) => {
if (info.data.rootID === stack.id) {
focusByOffset(protyle.title.editElement, stack.position.start, stack.position.end);
} else {
- Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${stack.id}"]`)).find(item => {
+ Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${stack.id}"]`)).find((item: HTMLElement) => {
if (!hasClosestByAttribute(item, "data-type", "NodeBlockQueryEmbed")) {
blockElement = item;
return true;
@@ -116,7 +117,7 @@ const focusStack = async (stack: IBackStack) => {
focusByOffset(stack.protyle.title.editElement, stack.position.start, stack.position.end);
return true;
}
- Array.from(stack.protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${stack.id}"]`)).find(item => {
+ Array.from(stack.protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${stack.id}"]`)).find((item: HTMLElement) => {
if (!hasClosestByAttribute(item, "data-type", "NodeBlockQueryEmbed")) {
blockElement = item;
return true;
@@ -127,17 +128,16 @@ const focusStack = async (stack: IBackStack) => {
// 切换 tab
stack.protyle.model.parent.parent.switchTab(stack.protyle.model.parent.headElement);
}
- if (stack.zoomId && stack.zoomId !== stack.protyle.block.id) {
- zoomOut(stack.protyle, stack.zoomId, undefined, false, () => {
- focusByOffset(getContenteditableElement(blockElement), stack.position.start, stack.position.end);
- scrollCenter(stack.protyle, blockElement, true);
- });
- return true;
- }
focusByOffset(getContenteditableElement(blockElement), stack.position.start, stack.position.end);
scrollCenter(stack.protyle, blockElement, true);
+ getAllModels().outline.forEach(item => {
+ if (item.blockId === stack.protyle.block.rootID) {
+ item.setCurrent(blockElement);
+ }
+ });
return true;
}
+ // 缩放
if (stack.protyle.element.parentElement) {
const response = await fetchSyncPost("/api/block/checkBlockExist", {id: stack.id});
if (!response.data) {
@@ -147,22 +147,23 @@ const focusStack = async (stack: IBackStack) => {
}
return false;
}
- fetchPost("/api/filetree/getDoc", {
- id: stack.zoomId ? stack.zoomId : stack.id,
- mode: stack.zoomId ? 0 : 3,
- size: stack.zoomId ? Constants.SIZE_GET_MAX : window.siyuan.config.editor.dynamicLoadBlocks,
- }, getResponse => {
- onGet(getResponse, stack.protyle, stack.zoomId ? [Constants.CB_GET_HTML, Constants.CB_GET_ALL] : [Constants.CB_GET_HTML]);
- Array.from(stack.protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${stack.id}"]`)).find(item => {
+ zoomOut(stack.protyle, stack.zoomId || stack.protyle.block.rootID, undefined, false, () => {
+ Array.from(stack.protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${stack.id}"]`)).find((item: HTMLElement) => {
if (!hasClosestByAttribute(item, "data-type", "NodeBlockQueryEmbed")) {
blockElement = item;
return true;
}
});
+ if (!blockElement) {
+ return;
+ }
+ getAllModels().outline.forEach(item => {
+ if (item.blockId === stack.protyle.block.rootID) {
+ item.setCurrent(blockElement);
+ }
+ });
focusByOffset(getContenteditableElement(blockElement), stack.position.start, stack.position.end);
- setTimeout(() => {
- scrollCenter(stack.protyle, blockElement);
- }, Constants.TIMEOUT_INPUT);
+ scrollCenter(stack.protyle, blockElement, true);
});
return true;
}