This commit is contained in:
parent
459b700e26
commit
c33e9429cd
8 changed files with 38 additions and 25 deletions
|
@ -119,11 +119,11 @@ export const initBar = (app: App) => {
|
|||
event.stopPropagation();
|
||||
break;
|
||||
} else if (targetId === "barExit") {
|
||||
event.stopPropagation();
|
||||
exportLayout({
|
||||
errorExit: true,
|
||||
cb: exitSiYuan,
|
||||
});
|
||||
event.stopPropagation();
|
||||
break;
|
||||
} else if (targetId === "barMode") {
|
||||
if (!window.siyuan.menus.menu.element.classList.contains("fn__none") &&
|
||||
|
|
|
@ -225,18 +225,19 @@ export const saveLayout = () => {
|
|||
}
|
||||
};
|
||||
|
||||
export const exportLayout = (options: {
|
||||
export const exportLayout = async (options: {
|
||||
cb: () => void,
|
||||
errorExit: boolean
|
||||
}) => {
|
||||
const editors = getAllModels().editor
|
||||
for (let i = 0; i < editors.length; i++) {
|
||||
await saveScroll(editors[i].editor.protyle);
|
||||
}
|
||||
if (isWindow()) {
|
||||
const layoutJSON: any = {
|
||||
layout: {},
|
||||
};
|
||||
layoutToJSON(window.siyuan.layout.layout, layoutJSON.layout);
|
||||
getAllModels().editor.forEach(item => {
|
||||
saveScroll(item.editor.protyle);
|
||||
});
|
||||
sessionStorage.setItem("layout", JSON.stringify(layoutJSON));
|
||||
options.cb();
|
||||
return;
|
||||
|
@ -253,10 +254,6 @@ export const exportLayout = (options: {
|
|||
right: dockToJSON(window.siyuan.layout.rightDock),
|
||||
};
|
||||
layoutToJSON(window.siyuan.layout.layout, layoutJSON.layout);
|
||||
getAllModels().editor.forEach(item => {
|
||||
saveScroll(item.editor.protyle);
|
||||
});
|
||||
|
||||
if (window.siyuan.config.readonly) {
|
||||
options.cb();
|
||||
} else {
|
||||
|
|
|
@ -170,9 +170,9 @@ export const initRightMenu = (app: App) => {
|
|||
event.stopPropagation();
|
||||
break;
|
||||
} else if (target.id === "menuSafeQuit") {
|
||||
exitSiYuan();
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
exitSiYuan();
|
||||
break;
|
||||
} else if (target.id === "menuAbout") {
|
||||
initAbout();
|
||||
|
|
|
@ -39,8 +39,13 @@ export const saveScroll = (protyle: IProtyle, getObject = false) => {
|
|||
if (getObject) {
|
||||
return attr;
|
||||
}
|
||||
|
||||
window.siyuan.storage[Constants.LOCAL_FILEPOSITION][protyle.block.rootID] = attr;
|
||||
setStorageVal(Constants.LOCAL_FILEPOSITION, window.siyuan.storage[Constants.LOCAL_FILEPOSITION]);
|
||||
return new Promise(resolve => {
|
||||
setStorageVal(Constants.LOCAL_FILEPOSITION, window.siyuan.storage[Constants.LOCAL_FILEPOSITION], () => {
|
||||
resolve(true);
|
||||
});
|
||||
})
|
||||
};
|
||||
|
||||
export const getDocByScroll = (options: {
|
||||
|
|
|
@ -300,7 +300,6 @@ export const setStorageVal = (key: string, val: any, cb?: () => void) => {
|
|||
if (window.siyuan.config.readonly) {
|
||||
return;
|
||||
}
|
||||
|
||||
fetchPost("/api/storage/setLocalStorageVal", {
|
||||
app: Constants.SIYUAN_APPID,
|
||||
key,
|
||||
|
|
|
@ -54,7 +54,7 @@ export const reloadProtyle = (protyle: IProtyle, focus: boolean, updateReadonly?
|
|||
getDocByScroll({
|
||||
protyle,
|
||||
focus,
|
||||
scrollAttr: saveScroll(protyle, true),
|
||||
scrollAttr: saveScroll(protyle, true) as IScrollAttr,
|
||||
updateReadonly
|
||||
});
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ const focusStack = async (app: App, stack: IBackStack) => {
|
|||
title: info.data.rootTitle,
|
||||
docIcon: info.data.rootIcon,
|
||||
callback(tab) {
|
||||
const scrollAttr = saveScroll(stack.protyle, true);
|
||||
const scrollAttr = saveScroll(stack.protyle, true) as IScrollAttr;
|
||||
scrollAttr.rootId = stack.protyle.block.rootID;
|
||||
scrollAttr.focusId = stack.id;
|
||||
scrollAttr.focusStart = stack.position.start;
|
||||
|
|
|
@ -24,18 +24,30 @@ export const processMessage = (response: IWebSocketData) => {
|
|||
if ("reloadui" === response.cmd) {
|
||||
if (response.data?.resetScroll) {
|
||||
window.siyuan.storage[Constants.LOCAL_FILEPOSITION] = {};
|
||||
setStorageVal(Constants.LOCAL_FILEPOSITION, window.siyuan.storage[Constants.LOCAL_FILEPOSITION]);
|
||||
}
|
||||
/// #if MOBILE
|
||||
window.location.reload();
|
||||
/// #else
|
||||
exportLayout({
|
||||
cb() {
|
||||
setStorageVal(Constants.LOCAL_FILEPOSITION, window.siyuan.storage[Constants.LOCAL_FILEPOSITION], () => {
|
||||
/// #if MOBILE
|
||||
window.location.reload();
|
||||
},
|
||||
errorExit: false,
|
||||
});
|
||||
/// #endif
|
||||
/// #else
|
||||
exportLayout({
|
||||
cb() {
|
||||
window.location.reload();
|
||||
},
|
||||
errorExit: false,
|
||||
});
|
||||
/// #endif
|
||||
});
|
||||
} else {
|
||||
/// #if MOBILE
|
||||
window.location.reload();
|
||||
/// #else
|
||||
exportLayout({
|
||||
cb() {
|
||||
window.location.reload();
|
||||
},
|
||||
errorExit: false,
|
||||
});
|
||||
/// #endif
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue