This commit is contained in:
Vanessa 2023-02-28 18:56:35 +08:00
parent e772e97b72
commit d44a928463

View file

@ -20,7 +20,7 @@ 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: Element;
if (!stack.protyle.element.parentElement) { 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) {
// 页签删除 // 页签删除
@ -74,32 +74,31 @@ const focusStack = async (stack: IBackStack) => {
wnd.addTab(tab); wnd.addTab(tab);
} }
wnd.showHeading(); wnd.showHeading();
// 页签关闭 // 替换被关闭的 protyle
setTimeout(() => { const protyle = (tab.model as Editor).editor.protyle;
const protyle = (tab.model as Editor).editor.protyle; stack.protyle = protyle;
forwardStack.find(item => { forwardStack.forEach(item => {
if (!item.protyle.element.parentElement && item.protyle.block.rootID === protyle.block.rootID) { if (!document.contains(item.protyle.element) && item.protyle.block.rootID === info.data.rootID) {
item.protyle = protyle; item.protyle = protyle;
}
});
window.siyuan.backStack.find(item => {
if (!item.protyle.element.parentElement && item.protyle.block.rootID === protyle.block.rootID) {
item.protyle = protyle;
}
});
if (protyle.block.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 => {
if (!hasClosestByAttribute(item, "data-type", "NodeBlockQueryEmbed")) {
blockElement = item;
return true;
}
});
focusByOffset(getContenteditableElement(blockElement), stack.position.start, stack.position.end);
scrollCenter(protyle, blockElement);
} }
}, 500); });
window.siyuan.backStack.forEach(item => {
if (!document.contains(item.protyle.element) && item.protyle.block.rootID === info.data.rootID) {
item.protyle = protyle;
}
});
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 => {
if (!hasClosestByAttribute(item, "data-type", "NodeBlockQueryEmbed")) {
blockElement = item;
return true;
}
});
focusByOffset(getContenteditableElement(blockElement), stack.position.start, stack.position.end);
scrollCenter(protyle, blockElement);
}
return true; return true;
} else { } else {
return false; return false;
@ -193,7 +192,9 @@ export const goBack = async () => {
return; return;
} }
document.querySelector("#barForward")?.classList.remove("toolbar__item--disabled"); document.querySelector("#barForward")?.classList.remove("toolbar__item--disabled");
if (!previousIsBack) { if (!previousIsBack &&
// 页签被关闭时应优先打开该页签,页签存在时即可返回上一步,不用再重置光标到该页签上
document.contains(window.siyuan.backStack[window.siyuan.backStack.length - 1].protyle.element)) {
forwardStack.push(window.siyuan.backStack.pop()); forwardStack.push(window.siyuan.backStack.pop());
} }
let stack = window.siyuan.backStack.pop(); let stack = window.siyuan.backStack.pop();