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_AI = "local-ai";
|
||||||
public static readonly LOCAL_PLUGINTOPUNPIN = "local-plugintopunpin";
|
public static readonly LOCAL_PLUGINTOPUNPIN = "local-plugintopunpin";
|
||||||
public static readonly LOCAL_FLASHCARD = "local-flashcard";
|
public static readonly LOCAL_FLASHCARD = "local-flashcard";
|
||||||
|
public static readonly LOCAL_FILEPOSITION = "local-fileposition";
|
||||||
|
|
||||||
// timeout
|
// timeout
|
||||||
public static readonly TIMEOUT_DBLCLICK = 190;
|
public static readonly TIMEOUT_DBLCLICK = 190;
|
||||||
|
|
|
||||||
|
|
@ -231,11 +231,11 @@ export const copyTab = (app: App, tab: Tab) => {
|
||||||
callback(newTab: Tab) {
|
callback(newTab: Tab) {
|
||||||
let model: Model;
|
let model: Model;
|
||||||
if (tab.model instanceof Editor) {
|
if (tab.model instanceof Editor) {
|
||||||
|
saveScroll(tab.model.editor.protyle);
|
||||||
model = new Editor({
|
model = new Editor({
|
||||||
app,
|
app,
|
||||||
tab: newTab,
|
tab: newTab,
|
||||||
blockId: tab.model.editor.protyle.block.id,
|
blockId: tab.model.editor.protyle.block.id
|
||||||
scrollAttr: saveScroll(tab.model.editor.protyle, true)
|
|
||||||
});
|
});
|
||||||
} else if (tab.model instanceof Asset) {
|
} else if (tab.model instanceof Asset) {
|
||||||
model = new Asset({
|
model = new Asset({
|
||||||
|
|
|
||||||
|
|
@ -178,13 +178,12 @@ export const exportLayout = (options: {
|
||||||
cb?: () => void,
|
cb?: () => void,
|
||||||
onlyData: boolean,
|
onlyData: boolean,
|
||||||
errorExit: boolean,
|
errorExit: boolean,
|
||||||
dropEditScroll?: boolean
|
|
||||||
}) => {
|
}) => {
|
||||||
if (isWindow()) {
|
if (isWindow()) {
|
||||||
const layoutJSON: any = {
|
const layoutJSON: any = {
|
||||||
layout: {},
|
layout: {},
|
||||||
};
|
};
|
||||||
layoutToJSON(window.siyuan.layout.layout, layoutJSON.layout, !!options.dropEditScroll);
|
layoutToJSON(window.siyuan.layout.layout, layoutJSON.layout);
|
||||||
if (options.onlyData) {
|
if (options.onlyData) {
|
||||||
return layoutJSON;
|
return layoutJSON;
|
||||||
}
|
}
|
||||||
|
|
@ -207,7 +206,7 @@ export const exportLayout = (options: {
|
||||||
left: dockToJSON(window.siyuan.layout.leftDock),
|
left: dockToJSON(window.siyuan.layout.leftDock),
|
||||||
right: dockToJSON(window.siyuan.layout.rightDock),
|
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) {
|
if (options.onlyData) {
|
||||||
return layoutJSON;
|
return layoutJSON;
|
||||||
}
|
}
|
||||||
|
|
@ -308,10 +307,6 @@ export const JSONToCenter = (app: App, json: ILayoutJSON, layout?: Layout | Wnd
|
||||||
if (window.siyuan.config.fileTree.openFilesUseCurrentTab) {
|
if (window.siyuan.config.fileTree.openFilesUseCurrentTab) {
|
||||||
(layout as Tab).headElement.classList.add("item--unupdate");
|
(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));
|
(layout as Tab).headElement.setAttribute("data-initdata", JSON.stringify(json));
|
||||||
} else if (json.instance === "Asset") {
|
} else if (json.instance === "Asset") {
|
||||||
(layout as Tab).addModel(new Asset({
|
(layout as Tab).addModel(new Asset({
|
||||||
|
|
@ -431,7 +426,7 @@ export const JSONToLayout = (app: App, isStart: boolean) => {
|
||||||
resizeTopBar();
|
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) {
|
if (layout instanceof Layout) {
|
||||||
json.direction = layout.direction;
|
json.direction = layout.direction;
|
||||||
if (layout.parent) {
|
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.mode = layout.editor.protyle.preview.element.classList.contains("fn__none") ? "wysiwyg" : "preview";
|
||||||
json.action = layout.editor.protyle.block.showAll ? Constants.CB_GET_ALL : "";
|
json.action = layout.editor.protyle.block.showAll ? Constants.CB_GET_ALL : "";
|
||||||
json.instance = "Editor";
|
json.instance = "Editor";
|
||||||
if (!dropEditScroll) {
|
saveScroll(layout.editor.protyle);
|
||||||
json.scrollAttr = saveScroll(layout.editor.protyle, true);
|
|
||||||
}
|
|
||||||
} else if (layout instanceof Asset) {
|
} else if (layout instanceof Asset) {
|
||||||
json.path = layout.path;
|
json.path = layout.path;
|
||||||
if (layout.pdfObject) {
|
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) => {
|
layout.children.forEach((item: Layout | Wnd | Tab) => {
|
||||||
const itemJSON = {};
|
const itemJSON = {};
|
||||||
json.children.push(itemJSON);
|
json.children.push(itemJSON);
|
||||||
layoutToJSON(item, itemJSON, dropEditScroll);
|
layoutToJSON(item, itemJSON);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if (layout instanceof Tab) {
|
} else if (layout instanceof Tab) {
|
||||||
if (layout.model) {
|
if (layout.model) {
|
||||||
json.children = {};
|
json.children = {};
|
||||||
layoutToJSON(layout.model, json.children, dropEditScroll);
|
layoutToJSON(layout.model, json.children);
|
||||||
} else if (layout.headElement) {
|
} else if (layout.headElement) {
|
||||||
// 当前页签没有激活时编辑器没有初始化
|
// 当前页签没有激活时编辑器没有初始化
|
||||||
json.children = JSON.parse(layout.headElement.getAttribute("data-initdata") || "{}");
|
json.children = JSON.parse(layout.headElement.getAttribute("data-initdata") || "{}");
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import {getSelectionOffset} from "../util/selection";
|
||||||
import {fetchPost} from "../../util/fetch";
|
import {fetchPost} from "../../util/fetch";
|
||||||
import {onGet} from "../util/onGet";
|
import {onGet} from "../util/onGet";
|
||||||
import {Constants} from "../../constants";
|
import {Constants} from "../../constants";
|
||||||
|
import {setStorageVal} from "../util/compatibility";
|
||||||
|
|
||||||
export const saveScroll = (protyle: IProtyle, getObject = false) => {
|
export const saveScroll = (protyle: IProtyle, getObject = false) => {
|
||||||
if (!protyle.wysiwyg.element.firstElementChild || window.siyuan.config.readonly) {
|
if (!protyle.wysiwyg.element.firstElementChild || window.siyuan.config.readonly) {
|
||||||
|
|
@ -38,10 +39,8 @@ export const saveScroll = (protyle: IProtyle, getObject = false) => {
|
||||||
if (getObject) {
|
if (getObject) {
|
||||||
return attr;
|
return attr;
|
||||||
}
|
}
|
||||||
const jsonAttr = JSON.stringify(attr);
|
window.siyuan.storage[Constants.LOCAL_FILEPOSITION][protyle.block.rootID] = JSON.stringify(attr);
|
||||||
fetchPost("/api/attr/setBlockAttrs", {id: protyle.block.rootID, attrs: {scroll: jsonAttr}}, () => {
|
setStorageVal(Constants.LOCAL_FILEPOSITION, window.siyuan.storage[Constants.LOCAL_FILEPOSITION][protyle.block.rootID]);
|
||||||
protyle.wysiwyg.element.setAttribute("scroll", jsonAttr);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getDocByScroll = (options: {
|
export const getDocByScroll = (options: {
|
||||||
|
|
|
||||||
|
|
@ -187,6 +187,7 @@ export const getLocalStorage = (cb: () => void) => {
|
||||||
defaultStorage[Constants.LOCAL_LAYOUTS] = []; // {name: "", layout:{}}
|
defaultStorage[Constants.LOCAL_LAYOUTS] = []; // {name: "", layout:{}}
|
||||||
defaultStorage[Constants.LOCAL_AI] = []; // {name: "", memo: ""}
|
defaultStorage[Constants.LOCAL_AI] = []; // {name: "", memo: ""}
|
||||||
defaultStorage[Constants.LOCAL_PLUGINTOPUNPIN] = [];
|
defaultStorage[Constants.LOCAL_PLUGINTOPUNPIN] = [];
|
||||||
|
defaultStorage[Constants.LOCAL_FILEPOSITION] = {}; // {id: IScrollAttr}
|
||||||
defaultStorage[Constants.LOCAL_FLASHCARD] = {
|
defaultStorage[Constants.LOCAL_FLASHCARD] = {
|
||||||
fullscreen: false
|
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_EXPORTIMG, Constants.LOCAL_SEARCHKEYS, Constants.LOCAL_PDFTHEME, Constants.LOCAL_BAZAAR,
|
||||||
Constants.LOCAL_EXPORTWORD, Constants.LOCAL_EXPORTPDF, Constants.LOCAL_DOCINFO, Constants.LOCAL_FONTSTYLES,
|
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_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") {
|
if (typeof response.data[key] === "string") {
|
||||||
try {
|
try {
|
||||||
const parseData = JSON.parse(response.data[key]);
|
const parseData = JSON.parse(response.data[key]);
|
||||||
|
|
@ -262,14 +264,6 @@ export const getLocalStorage = (cb: () => void) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
cb();
|
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);
|
const ialKeys = Object.keys(ial);
|
||||||
for (let i = 0; i < this.element.attributes.length; i++) {
|
for (let i = 0; i < this.element.attributes.length; i++) {
|
||||||
const oldKey = this.element.attributes[i].nodeName;
|
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)) {
|
!ialKeys.includes(oldKey)) {
|
||||||
this.element.removeAttribute(oldKey);
|
this.element.removeAttribute(oldKey);
|
||||||
i--;
|
i--;
|
||||||
|
|
|
||||||
|
|
@ -52,10 +52,10 @@ const focusStack = async (app: App, stack: IBackStack) => {
|
||||||
scrollAttr.focusId = stack.id;
|
scrollAttr.focusId = stack.id;
|
||||||
scrollAttr.focusStart = stack.position.start;
|
scrollAttr.focusStart = stack.position.start;
|
||||||
scrollAttr.focusEnd = stack.position.end;
|
scrollAttr.focusEnd = stack.position.end;
|
||||||
|
window.siyuan.storage[Constants.LOCAL_FILEPOSITION][stack.protyle.block.rootID] = scrollAttr;
|
||||||
const editor = new Editor({
|
const editor = new Editor({
|
||||||
app: app,
|
app: app,
|
||||||
tab,
|
tab,
|
||||||
scrollAttr,
|
|
||||||
blockId: stack.zoomId || stack.protyle.block.rootID,
|
blockId: stack.zoomId || stack.protyle.block.rootID,
|
||||||
action: stack.zoomId ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS]
|
action: stack.zoomId ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS]
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
import {exportLayout} from "../layout/util";
|
import {exportLayout} from "../layout/util";
|
||||||
/// #endif
|
/// #endif
|
||||||
import {hideMessage, showMessage} from "../dialog/message";
|
import {hideMessage, showMessage} from "../dialog/message";
|
||||||
|
import {setStorageVal} from "../protyle/util/compatibility";
|
||||||
|
import {Constants} from "../constants";
|
||||||
|
|
||||||
export const processMessage = (response: IWebSocketData) => {
|
export const processMessage = (response: IWebSocketData) => {
|
||||||
if ("msg" === response.cmd) {
|
if ("msg" === response.cmd) {
|
||||||
|
|
@ -20,6 +22,10 @@ export const processMessage = (response: IWebSocketData) => {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ("reloadui" === response.cmd) {
|
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
|
/// #if MOBILE
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
/// #else
|
/// #else
|
||||||
|
|
@ -27,7 +33,6 @@ export const processMessage = (response: IWebSocketData) => {
|
||||||
reload: true,
|
reload: true,
|
||||||
onlyData: false,
|
onlyData: false,
|
||||||
errorExit: false,
|
errorExit: false,
|
||||||
dropEditScroll: response.data?.resetScroll,
|
|
||||||
});
|
});
|
||||||
/// #endif
|
/// #endif
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue