This commit is contained in:
Vanessa 2023-05-15 11:46:51 +08:00
parent 53a95ffbf7
commit 6690084caa
5 changed files with 32 additions and 23 deletions

View file

@ -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 = "";

View file

@ -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 {

View file

@ -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) {

View file

@ -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";

View file

@ -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;
}