Vanessa 2023-06-01 14:56:21 +08:00
parent 8c35440a77
commit 74b4a00a2f
42 changed files with 426 additions and 270 deletions

View file

@ -11,10 +11,11 @@ import {setStorageVal} from "../../protyle/util/compatibility";
import {closePanel} from "./closePanel";
import {showMessage} from "../../dialog/message";
import {getCurrentEditor} from "../editor";
import {App} from "../../index";
const forwardStack: IBackStack[] = [];
const focusStack = (backStack: IBackStack) => {
const focusStack = (backStack: IBackStack, app: App) => {
const protyle = getCurrentEditor().protyle;
window.siyuan.storage[Constants.LOCAL_DOCINFO] = {
id: backStack.id,
@ -50,8 +51,14 @@ const focusStack = (backStack: IBackStack) => {
if (backStack.zoomId !== protyle.block.id) {
fetchPost("/api/block/checkBlockExist", {id: backStack.id}, existResponse => {
if (existResponse.data) {
zoomOut(protyle, backStack.id, undefined, false, () => {
protyle.contentElement.scrollTop = backStack.scrollTop;
zoomOut({
app,
protyle,
id: backStack.id,
isPushBack: false,
callback: () => {
protyle.contentElement.scrollTop = backStack.scrollTop;
}
});
}
});
@ -104,7 +111,7 @@ export const pushBack = () => {
});
};
export const goForward = () => {
export const goForward = (app: App) => {
if (window.siyuan.menus.menu.element.classList.contains("b3-menu--fullscreen") &&
!window.siyuan.menus.menu.element.classList.contains("fn__none")) {
window.siyuan.menus.menu.element.dispatchEvent(new CustomEvent("click", {detail: "back"}));
@ -123,10 +130,10 @@ export const goForward = () => {
return;
}
window.siyuan.backStack.push(forwardStack.pop());
focusStack(forwardStack[forwardStack.length - 1]);
focusStack(forwardStack[forwardStack.length - 1], app);
};
export const goBack = () => {
export const goBack = (app: App) => {
const editor = getCurrentEditor();
if (window.siyuan.menus.menu.element.classList.contains("b3-menu--fullscreen") &&
!window.siyuan.menus.menu.element.classList.contains("fn__none")) {
@ -174,5 +181,5 @@ export const goBack = () => {
}
const item = window.siyuan.backStack.pop();
forwardStack.push(item);
focusStack(item);
focusStack(item, app);
};

View file

@ -23,7 +23,7 @@ import {App} from "../../index";
export const initFramework = (app: App) => {
setInlineStyle();
renderSnippet();
initKeyboardToolbar();
initKeyboardToolbar(app);
const sidebarElement = document.getElementById("sidebar");
let outline: MobileOutline;
let backlink: MobileBacklinks;

View file

@ -4,6 +4,7 @@ import {moveToDown, moveToUp} from "../../protyle/wysiwyg/move";
import {Constants} from "../../constants";
import {focusByRange, getSelectionPosition} from "../../protyle/util/selection";
import {getCurrentEditor} from "../editor";
import {App} from "../../index";
let renderKeyboardToolbarTimeout: number;
let showUtil = false;
@ -327,7 +328,7 @@ export const activeBlur = () => {
(document.activeElement as HTMLElement).blur();
};
export const initKeyboardToolbar = () => {
export const initKeyboardToolbar = (app: App) => {
let preventRender = false;
document.addEventListener("selectionchange", () => {
if (!preventRender) {
@ -416,10 +417,10 @@ export const initKeyboardToolbar = () => {
return;
}
if (type === "undo") {
protyle.undo.undo(protyle);
protyle.undo.undo(app, protyle);
return;
} else if (type === "redo") {
protyle.undo.redo(protyle);
protyle.undo.redo(app, protyle);
return;
}
if (getSelection().rangeCount === 0) {
@ -475,7 +476,7 @@ export const initKeyboardToolbar = () => {
}
return;
} else if (type === "more") {
protyle.breadcrumb.showMenu(protyle, {
protyle.breadcrumb.showMenu(app, protyle, {
x: 0,
y: 0
});