mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-18 15:40:12 +01:00
This commit is contained in:
parent
d2cf402c6a
commit
2d11266b31
8 changed files with 23 additions and 31 deletions
|
|
@ -100,6 +100,7 @@ export abstract class Constants {
|
|||
public static readonly LOCAL_AI = "local-ai";
|
||||
public static readonly LOCAL_PLUGINTOPUNPIN = "local-plugintopunpin";
|
||||
public static readonly LOCAL_FLASHCARD = "local-flashcard";
|
||||
public static readonly LOCAL_FILEPOSITION = "local-fileposition";
|
||||
|
||||
// timeout
|
||||
public static readonly TIMEOUT_DBLCLICK = 190;
|
||||
|
|
|
|||
|
|
@ -231,11 +231,11 @@ export const copyTab = (app: App, tab: Tab) => {
|
|||
callback(newTab: Tab) {
|
||||
let model: Model;
|
||||
if (tab.model instanceof Editor) {
|
||||
saveScroll(tab.model.editor.protyle);
|
||||
model = new Editor({
|
||||
app,
|
||||
tab: newTab,
|
||||
blockId: tab.model.editor.protyle.block.id,
|
||||
scrollAttr: saveScroll(tab.model.editor.protyle, true)
|
||||
blockId: tab.model.editor.protyle.block.id
|
||||
});
|
||||
} else if (tab.model instanceof Asset) {
|
||||
model = new Asset({
|
||||
|
|
|
|||
|
|
@ -178,13 +178,12 @@ export const exportLayout = (options: {
|
|||
cb?: () => void,
|
||||
onlyData: boolean,
|
||||
errorExit: boolean,
|
||||
dropEditScroll?: boolean
|
||||
}) => {
|
||||
if (isWindow()) {
|
||||
const layoutJSON: any = {
|
||||
layout: {},
|
||||
};
|
||||
layoutToJSON(window.siyuan.layout.layout, layoutJSON.layout, !!options.dropEditScroll);
|
||||
layoutToJSON(window.siyuan.layout.layout, layoutJSON.layout);
|
||||
if (options.onlyData) {
|
||||
return layoutJSON;
|
||||
}
|
||||
|
|
@ -207,7 +206,7 @@ export const exportLayout = (options: {
|
|||
left: dockToJSON(window.siyuan.layout.leftDock),
|
||||
right: dockToJSON(window.siyuan.layout.rightDock),
|
||||
};
|
||||
layoutToJSON(window.siyuan.layout.layout, layoutJSON.layout, !!options.dropEditScroll);
|
||||
layoutToJSON(window.siyuan.layout.layout, layoutJSON.layout);
|
||||
if (options.onlyData) {
|
||||
return layoutJSON;
|
||||
}
|
||||
|
|
@ -308,10 +307,6 @@ export const JSONToCenter = (app: App, json: ILayoutJSON, layout?: Layout | Wnd
|
|||
if (window.siyuan.config.fileTree.openFilesUseCurrentTab) {
|
||||
(layout as Tab).headElement.classList.add("item--unupdate");
|
||||
}
|
||||
if (json.scrollAttr) {
|
||||
// 历史数据兼容
|
||||
json.scrollAttr.rootId = json.rootId;
|
||||
}
|
||||
(layout as Tab).headElement.setAttribute("data-initdata", JSON.stringify(json));
|
||||
} else if (json.instance === "Asset") {
|
||||
(layout as Tab).addModel(new Asset({
|
||||
|
|
@ -431,7 +426,7 @@ export const JSONToLayout = (app: App, isStart: boolean) => {
|
|||
resizeTopBar();
|
||||
};
|
||||
|
||||
export const layoutToJSON = (layout: Layout | Wnd | Tab | Model, json: any, dropEditScroll = false) => {
|
||||
export const layoutToJSON = (layout: Layout | Wnd | Tab | Model, json: any) => {
|
||||
if (layout instanceof Layout) {
|
||||
json.direction = layout.direction;
|
||||
if (layout.parent) {
|
||||
|
|
@ -480,9 +475,7 @@ export const layoutToJSON = (layout: Layout | Wnd | Tab | Model, json: any, drop
|
|||
json.mode = layout.editor.protyle.preview.element.classList.contains("fn__none") ? "wysiwyg" : "preview";
|
||||
json.action = layout.editor.protyle.block.showAll ? Constants.CB_GET_ALL : "";
|
||||
json.instance = "Editor";
|
||||
if (!dropEditScroll) {
|
||||
json.scrollAttr = saveScroll(layout.editor.protyle, true);
|
||||
}
|
||||
saveScroll(layout.editor.protyle);
|
||||
} else if (layout instanceof Asset) {
|
||||
json.path = layout.path;
|
||||
if (layout.pdfObject) {
|
||||
|
|
@ -549,13 +542,13 @@ export const layoutToJSON = (layout: Layout | Wnd | Tab | Model, json: any, drop
|
|||
layout.children.forEach((item: Layout | Wnd | Tab) => {
|
||||
const itemJSON = {};
|
||||
json.children.push(itemJSON);
|
||||
layoutToJSON(item, itemJSON, dropEditScroll);
|
||||
layoutToJSON(item, itemJSON);
|
||||
});
|
||||
}
|
||||
} else if (layout instanceof Tab) {
|
||||
if (layout.model) {
|
||||
json.children = {};
|
||||
layoutToJSON(layout.model, json.children, dropEditScroll);
|
||||
layoutToJSON(layout.model, json.children);
|
||||
} else if (layout.headElement) {
|
||||
// 当前页签没有激活时编辑器没有初始化
|
||||
json.children = JSON.parse(layout.headElement.getAttribute("data-initdata") || "{}");
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import {getSelectionOffset} from "../util/selection";
|
|||
import {fetchPost} from "../../util/fetch";
|
||||
import {onGet} from "../util/onGet";
|
||||
import {Constants} from "../../constants";
|
||||
import {setStorageVal} from "../util/compatibility";
|
||||
|
||||
export const saveScroll = (protyle: IProtyle, getObject = false) => {
|
||||
if (!protyle.wysiwyg.element.firstElementChild || window.siyuan.config.readonly) {
|
||||
|
|
@ -38,10 +39,8 @@ export const saveScroll = (protyle: IProtyle, getObject = false) => {
|
|||
if (getObject) {
|
||||
return attr;
|
||||
}
|
||||
const jsonAttr = JSON.stringify(attr);
|
||||
fetchPost("/api/attr/setBlockAttrs", {id: protyle.block.rootID, attrs: {scroll: jsonAttr}}, () => {
|
||||
protyle.wysiwyg.element.setAttribute("scroll", jsonAttr);
|
||||
});
|
||||
window.siyuan.storage[Constants.LOCAL_FILEPOSITION][protyle.block.rootID] = JSON.stringify(attr);
|
||||
setStorageVal(Constants.LOCAL_FILEPOSITION, window.siyuan.storage[Constants.LOCAL_FILEPOSITION][protyle.block.rootID]);
|
||||
};
|
||||
|
||||
export const getDocByScroll = (options: {
|
||||
|
|
|
|||
|
|
@ -187,6 +187,7 @@ export const getLocalStorage = (cb: () => void) => {
|
|||
defaultStorage[Constants.LOCAL_LAYOUTS] = []; // {name: "", layout:{}}
|
||||
defaultStorage[Constants.LOCAL_AI] = []; // {name: "", memo: ""}
|
||||
defaultStorage[Constants.LOCAL_PLUGINTOPUNPIN] = [];
|
||||
defaultStorage[Constants.LOCAL_FILEPOSITION] = {}; // {id: IScrollAttr}
|
||||
defaultStorage[Constants.LOCAL_FLASHCARD] = {
|
||||
fullscreen: false
|
||||
};
|
||||
|
|
@ -244,7 +245,8 @@ export const getLocalStorage = (cb: () => void) => {
|
|||
[Constants.LOCAL_EXPORTIMG, Constants.LOCAL_SEARCHKEYS, Constants.LOCAL_PDFTHEME, Constants.LOCAL_BAZAAR,
|
||||
Constants.LOCAL_EXPORTWORD, Constants.LOCAL_EXPORTPDF, Constants.LOCAL_DOCINFO, Constants.LOCAL_FONTSTYLES,
|
||||
Constants.LOCAL_SEARCHDATA, Constants.LOCAL_ZOOM, Constants.LOCAL_LAYOUTS, Constants.LOCAL_AI,
|
||||
Constants.LOCAL_PLUGINTOPUNPIN, Constants.LOCAL_SEARCHASSET, Constants.LOCAL_FLASHCARD].forEach((key) => {
|
||||
Constants.LOCAL_PLUGINTOPUNPIN, Constants.LOCAL_SEARCHASSET, Constants.LOCAL_FLASHCARD,
|
||||
Constants.LOCAL_FILEPOSITION].forEach((key) => {
|
||||
if (typeof response.data[key] === "string") {
|
||||
try {
|
||||
const parseData = JSON.parse(response.data[key]);
|
||||
|
|
@ -262,14 +264,6 @@ export const getLocalStorage = (cb: () => void) => {
|
|||
}
|
||||
});
|
||||
cb();
|
||||
|
||||
if (!window.siyuan.config.readonly) {
|
||||
// 数据兼容,移除历史数据,3.8.4 移除
|
||||
fetchPost("/api/storage/removeLocalStorageVals", {
|
||||
app: Constants.SIYUAN_APPID,
|
||||
keys: ["leftColumn", "local-searchkey", "local-searchedata", "local-searchekeys", "local-searchetabdata", "rightColumn", "topBar"]
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ export class WYSIWYG {
|
|||
const ialKeys = Object.keys(ial);
|
||||
for (let i = 0; i < this.element.attributes.length; i++) {
|
||||
const oldKey = this.element.attributes[i].nodeName;
|
||||
if (!["type", "class", "spellcheck", "contenteditable", "data-doc-type", "style", "scroll", "data-realwidth"].includes(oldKey) &&
|
||||
if (!["type", "class", "spellcheck", "contenteditable", "data-doc-type", "style", "data-realwidth"].includes(oldKey) &&
|
||||
!ialKeys.includes(oldKey)) {
|
||||
this.element.removeAttribute(oldKey);
|
||||
i--;
|
||||
|
|
|
|||
|
|
@ -52,10 +52,10 @@ const focusStack = async (app: App, stack: IBackStack) => {
|
|||
scrollAttr.focusId = stack.id;
|
||||
scrollAttr.focusStart = stack.position.start;
|
||||
scrollAttr.focusEnd = stack.position.end;
|
||||
window.siyuan.storage[Constants.LOCAL_FILEPOSITION][stack.protyle.block.rootID] = scrollAttr;
|
||||
const editor = new Editor({
|
||||
app: app,
|
||||
tab,
|
||||
scrollAttr,
|
||||
blockId: stack.zoomId || stack.protyle.block.rootID,
|
||||
action: stack.zoomId ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS]
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
import {exportLayout} from "../layout/util";
|
||||
/// #endif
|
||||
import {hideMessage, showMessage} from "../dialog/message";
|
||||
import {setStorageVal} from "../protyle/util/compatibility";
|
||||
import {Constants} from "../constants";
|
||||
|
||||
export const processMessage = (response: IWebSocketData) => {
|
||||
if ("msg" === response.cmd) {
|
||||
|
|
@ -20,6 +22,10 @@ export const processMessage = (response: IWebSocketData) => {
|
|||
return false;
|
||||
}
|
||||
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
|
||||
|
|
@ -27,7 +33,6 @@ export const processMessage = (response: IWebSocketData) => {
|
|||
reload: true,
|
||||
onlyData: false,
|
||||
errorExit: false,
|
||||
dropEditScroll: response.data?.resetScroll,
|
||||
});
|
||||
/// #endif
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue