mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 14:40:12 +01:00
This commit is contained in:
parent
53a95ffbf7
commit
6690084caa
5 changed files with 32 additions and 23 deletions
|
|
@ -506,7 +506,7 @@ export const isCurrentEditor = (blockId: string) => {
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateOutline = (models: IModels, protyle: IProtyle, reload = false) => {
|
export const updateOutline = (models: IModels, protyle: IProtyle, reload = false) => {
|
||||||
models.outline.find(item => {
|
models.outline.find(item => {
|
||||||
if (reload || (item.type === "pin" && (!protyle || item.blockId !== protyle.block?.rootID))) {
|
if (reload || (item.type === "pin" && (!protyle || item.blockId !== protyle.block?.rootID))) {
|
||||||
let blockId = "";
|
let blockId = "";
|
||||||
|
|
|
||||||
|
|
@ -218,6 +218,9 @@ export class Outline extends Model {
|
||||||
}
|
}
|
||||||
|
|
||||||
public setCurrent(nodeElement: HTMLElement) {
|
public setCurrent(nodeElement: HTMLElement) {
|
||||||
|
if (!nodeElement) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (nodeElement.getAttribute("data-type") === "NodeHeading") {
|
if (nodeElement.getAttribute("data-type") === "NodeHeading") {
|
||||||
this.setCurrentById(nodeElement.getAttribute("data-node-id"));
|
this.setCurrentById(nodeElement.getAttribute("data-node-id"));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -493,7 +493,13 @@ export const zoomOut = (protyle: IProtyle, id: string, focusId?: string, isPushB
|
||||||
}
|
}
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
if (protyle.model) {
|
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
|
/// #endif
|
||||||
if (callback) {
|
if (callback) {
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ import {getEditorRange} from "../util/selection";
|
||||||
import {setPadding} from "../ui/initUI";
|
import {setPadding} from "../ui/initUI";
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
import {openFileById} from "../../editor/util";
|
import {openFileById} from "../../editor/util";
|
||||||
import {getAllModels} from "../../layout/getAll";
|
|
||||||
/// #endif
|
/// #endif
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER
|
||||||
import {getCurrentWindow, systemPreferences} from "@electron/remote";
|
import {getCurrentWindow, systemPreferences} from "@electron/remote";
|
||||||
|
|
|
||||||
|
|
@ -13,13 +13,14 @@ import {scrollCenter} from "./highlightById";
|
||||||
import {zoomOut} from "../menus/protyle";
|
import {zoomOut} from "../menus/protyle";
|
||||||
import {showMessage} from "../dialog/message";
|
import {showMessage} from "../dialog/message";
|
||||||
import {saveScroll} from "../protyle/scroll/saveScroll";
|
import {saveScroll} from "../protyle/scroll/saveScroll";
|
||||||
|
import {getAllModels} from "../layout/getAll";
|
||||||
|
|
||||||
let forwardStack: IBackStack[] = [];
|
let forwardStack: IBackStack[] = [];
|
||||||
let previousIsBack = false;
|
let previousIsBack = false;
|
||||||
|
|
||||||
const focusStack = async (stack: IBackStack) => {
|
const focusStack = async (stack: IBackStack) => {
|
||||||
hideElements(["gutter", "toolbar", "hint", "util", "dialog"], stack.protyle);
|
hideElements(["gutter", "toolbar", "hint", "util", "dialog"], stack.protyle);
|
||||||
let blockElement: Element;
|
let blockElement: HTMLElement;
|
||||||
if (!document.contains(stack.protyle.element)) {
|
if (!document.contains(stack.protyle.element)) {
|
||||||
const response = await fetchSyncPost("/api/block/checkBlockExist", {id: stack.protyle.block.rootID});
|
const response = await fetchSyncPost("/api/block/checkBlockExist", {id: stack.protyle.block.rootID});
|
||||||
if (!response.data) {
|
if (!response.data) {
|
||||||
|
|
@ -91,7 +92,7 @@ const focusStack = async (stack: IBackStack) => {
|
||||||
if (info.data.rootID === stack.id) {
|
if (info.data.rootID === stack.id) {
|
||||||
focusByOffset(protyle.title.editElement, stack.position.start, stack.position.end);
|
focusByOffset(protyle.title.editElement, stack.position.start, stack.position.end);
|
||||||
} else {
|
} 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")) {
|
if (!hasClosestByAttribute(item, "data-type", "NodeBlockQueryEmbed")) {
|
||||||
blockElement = item;
|
blockElement = item;
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -116,7 +117,7 @@ const focusStack = async (stack: IBackStack) => {
|
||||||
focusByOffset(stack.protyle.title.editElement, stack.position.start, stack.position.end);
|
focusByOffset(stack.protyle.title.editElement, stack.position.start, stack.position.end);
|
||||||
return true;
|
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")) {
|
if (!hasClosestByAttribute(item, "data-type", "NodeBlockQueryEmbed")) {
|
||||||
blockElement = item;
|
blockElement = item;
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -127,17 +128,16 @@ const focusStack = async (stack: IBackStack) => {
|
||||||
// 切换 tab
|
// 切换 tab
|
||||||
stack.protyle.model.parent.parent.switchTab(stack.protyle.model.parent.headElement);
|
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);
|
focusByOffset(getContenteditableElement(blockElement), stack.position.start, stack.position.end);
|
||||||
scrollCenter(stack.protyle, blockElement, true);
|
scrollCenter(stack.protyle, blockElement, true);
|
||||||
|
getAllModels().outline.forEach(item => {
|
||||||
|
if (item.blockId === stack.protyle.block.rootID) {
|
||||||
|
item.setCurrent(blockElement);
|
||||||
|
}
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
// 缩放
|
||||||
if (stack.protyle.element.parentElement) {
|
if (stack.protyle.element.parentElement) {
|
||||||
const response = await fetchSyncPost("/api/block/checkBlockExist", {id: stack.id});
|
const response = await fetchSyncPost("/api/block/checkBlockExist", {id: stack.id});
|
||||||
if (!response.data) {
|
if (!response.data) {
|
||||||
|
|
@ -147,22 +147,23 @@ const focusStack = async (stack: IBackStack) => {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
fetchPost("/api/filetree/getDoc", {
|
zoomOut(stack.protyle, stack.zoomId || stack.protyle.block.rootID, undefined, false, () => {
|
||||||
id: stack.zoomId ? stack.zoomId : stack.id,
|
Array.from(stack.protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${stack.id}"]`)).find((item: HTMLElement) => {
|
||||||
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 => {
|
|
||||||
if (!hasClosestByAttribute(item, "data-type", "NodeBlockQueryEmbed")) {
|
if (!hasClosestByAttribute(item, "data-type", "NodeBlockQueryEmbed")) {
|
||||||
blockElement = item;
|
blockElement = item;
|
||||||
return true;
|
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);
|
focusByOffset(getContenteditableElement(blockElement), stack.position.start, stack.position.end);
|
||||||
setTimeout(() => {
|
scrollCenter(stack.protyle, blockElement, true);
|
||||||
scrollCenter(stack.protyle, blockElement);
|
|
||||||
}, Constants.TIMEOUT_INPUT);
|
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue