mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-19 16:10:12 +01:00
This commit is contained in:
parent
e14ca5799b
commit
73505073e6
12 changed files with 42 additions and 59 deletions
|
|
@ -21,7 +21,7 @@ import {setEmpty} from "../mobile/util/setEmpty";
|
|||
import {hideAllElements, hideElements} from "../protyle/ui/hideElements";
|
||||
import {App} from "../index";
|
||||
import {saveScroll} from "../protyle/scroll/saveScroll";
|
||||
import {isInAndroid, isInIOS} from "../protyle/util/compatibility";
|
||||
import {isInAndroid, isInIOS, setStorageVal} from "../protyle/util/compatibility";
|
||||
import {Plugin} from "../plugin";
|
||||
|
||||
const updateTitle = (rootID: string, tab: Tab) => {
|
||||
|
|
@ -65,12 +65,14 @@ export const reloadSync = (app: App, data: { upsertRootIDs: string[], removeRoot
|
|||
reloadProtyle(item.editor.protyle, false);
|
||||
updateTitle(item.editor.protyle.block.rootID, item.parent);
|
||||
} else if (data.removeRootIDs.includes(item.editor.protyle.block.rootID)) {
|
||||
item.parent.parent.removeTab(item.parent.id, false, false, false);
|
||||
item.parent.parent.removeTab(item.parent.id, false, false);
|
||||
delete window.siyuan.storage[Constants.LOCAL_FILEPOSITION][item.editor.protyle.block.rootID];
|
||||
setStorageVal(Constants.LOCAL_FILEPOSITION, window.siyuan.storage[Constants.LOCAL_FILEPOSITION]);
|
||||
}
|
||||
});
|
||||
allModels.graph.forEach(item => {
|
||||
if (item.type === "local" && data.removeRootIDs.includes(item.rootId)) {
|
||||
item.parent.parent.removeTab(item.parent.id, false, false, false);
|
||||
item.parent.parent.removeTab(item.parent.id, false, false);
|
||||
} else if (item.type !== "local" || data.upsertRootIDs.includes(item.rootId)) {
|
||||
item.searchGraph(false);
|
||||
if (item.type === "local") {
|
||||
|
|
@ -80,7 +82,7 @@ export const reloadSync = (app: App, data: { upsertRootIDs: string[], removeRoot
|
|||
});
|
||||
allModels.outline.forEach(item => {
|
||||
if (item.type === "local" && data.removeRootIDs.includes(item.blockId)) {
|
||||
item.parent.parent.removeTab(item.parent.id, false, false, false);
|
||||
item.parent.parent.removeTab(item.parent.id, false, false);
|
||||
} else if (item.type !== "local" || data.upsertRootIDs.includes(item.blockId)) {
|
||||
fetchPost("/api/outline/getDocOutline", {
|
||||
id: item.blockId,
|
||||
|
|
@ -94,7 +96,7 @@ export const reloadSync = (app: App, data: { upsertRootIDs: string[], removeRoot
|
|||
});
|
||||
allModels.backlink.forEach(item => {
|
||||
if (item.type === "local" && data.removeRootIDs.includes(item.rootId)) {
|
||||
item.parent.parent.removeTab(item.parent.id, false, false, false);
|
||||
item.parent.parent.removeTab(item.parent.id, false, false);
|
||||
} else {
|
||||
item.refresh();
|
||||
if (item.type === "local") {
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@ export class Editor extends Model {
|
|||
app: App,
|
||||
tab: Tab,
|
||||
blockId: string,
|
||||
rootId?: string, // 使用 rootId 会优先使用本地 filepositon 定位
|
||||
mode?: TEditorMode,
|
||||
action?: string[],
|
||||
scrollAttr?: IScrollAttr
|
||||
}) {
|
||||
super({
|
||||
app: options.app,
|
||||
|
|
@ -38,19 +38,19 @@ export class Editor extends Model {
|
|||
private initProtyle(options: {
|
||||
blockId: string,
|
||||
action?: string[]
|
||||
rootId?: string,
|
||||
mode?: TEditorMode,
|
||||
scrollAttr?: IScrollAttr
|
||||
}) {
|
||||
this.editor = new Protyle(this.app, this.element, {
|
||||
action: options.action || [],
|
||||
blockId: options.blockId,
|
||||
rootId: options.rootId,
|
||||
mode: options.mode,
|
||||
render: {
|
||||
title: true,
|
||||
background: true,
|
||||
scroll: true,
|
||||
},
|
||||
scrollAttr: options.scrollAttr,
|
||||
typewriterMode: true,
|
||||
after: (editor) => {
|
||||
if (window.siyuan.editorIsFullscreen) {
|
||||
|
|
|
|||
|
|
@ -277,7 +277,7 @@ export const openFile = async (options: IOpenFileOptions) => {
|
|||
createdTab = newTab(options);
|
||||
wnd.addTab(createdTab);
|
||||
if (unUpdateTab && options.removeCurrentTab) {
|
||||
wnd.removeTab(unUpdateTab.id, false, true, false);
|
||||
wnd.removeTab(unUpdateTab.id, false, false);
|
||||
}
|
||||
} else {
|
||||
createdTab = newTab(options);
|
||||
|
|
@ -306,7 +306,6 @@ const getUnInitTab = (options: IOpenFileOptions) => {
|
|||
} else {
|
||||
initObj.action = options.action;
|
||||
}
|
||||
delete initObj.scrollAttr;
|
||||
item.headElement.setAttribute("data-initdata", JSON.stringify(initObj));
|
||||
item.parent.switchTab(item.headElement);
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -682,7 +682,7 @@ export class Wnd {
|
|||
model.send("closews", {});
|
||||
}
|
||||
|
||||
private removeTabAction = (id: string, closeAll = false, hasSaveScroll = true, animate = true) => {
|
||||
private removeTabAction = (id: string, closeAll = false, animate = true) => {
|
||||
clearCounter();
|
||||
this.children.find((item, index) => {
|
||||
if (item.id === id) {
|
||||
|
|
@ -691,7 +691,7 @@ export class Wnd {
|
|||
item.model.beforeDestroy();
|
||||
}
|
||||
}
|
||||
if (item.model instanceof Editor && hasSaveScroll) {
|
||||
if (item.model instanceof Editor) {
|
||||
saveScroll(item.model.editor.protyle);
|
||||
}
|
||||
if (this.children.length === 1) {
|
||||
|
|
@ -787,7 +787,7 @@ export class Wnd {
|
|||
/// #endif
|
||||
};
|
||||
|
||||
public removeTab(id: string, closeAll = false, needSaveScroll = true, animate = true) {
|
||||
public removeTab(id: string, closeAll = false, animate = true) {
|
||||
for (let index = 0; index < this.children.length; index++) {
|
||||
const item = this.children[index];
|
||||
if (item.id === id) {
|
||||
|
|
@ -796,9 +796,9 @@ export class Wnd {
|
|||
showMessage(window.siyuan.languages.uploading);
|
||||
return;
|
||||
}
|
||||
this.removeTabAction(id, closeAll, needSaveScroll, animate);
|
||||
this.removeTabAction(id, closeAll, animate);
|
||||
} else {
|
||||
this.removeTabAction(id, closeAll, needSaveScroll, animate);
|
||||
this.removeTabAction(id, closeAll, animate);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -304,10 +304,6 @@ export const copyTab = (app: App, tab: Tab) => {
|
|||
} else if (!tab.model && tab.headElement) {
|
||||
const initData = JSON.parse(tab.headElement.getAttribute("data-initdata") || "{}");
|
||||
if (initData) {
|
||||
// 历史数据兼容 2023-05-24
|
||||
if (initData.scrollAttr) {
|
||||
initData.scrollAttr.rootId = initData.rootId;
|
||||
}
|
||||
model = newModelByInitData(app, newTab, initData);
|
||||
}
|
||||
}
|
||||
|
|
@ -320,7 +316,7 @@ export const closeTabByType = async (tab: Tab, type: "closeOthers" | "closeAll"
|
|||
if (type === "closeOthers") {
|
||||
for (let index = 0; index < tab.parent.children.length; index++) {
|
||||
if (tab.parent.children[index].id !== tab.id && !tab.parent.children[index].headElement.classList.contains("item--pin")) {
|
||||
await tab.parent.children[index].parent.removeTab(tab.parent.children[index].id, true, true, false);
|
||||
await tab.parent.children[index].parent.removeTab(tab.parent.children[index].id, true, false);
|
||||
index--;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -378,7 +378,7 @@ export const JSONToLayout = (app: App, isStart: boolean) => {
|
|||
if (window.siyuan.config.fileTree.closeTabsOnStart && isStart) {
|
||||
getAllTabs().forEach(item => {
|
||||
if (item.headElement && !item.headElement.classList.contains("item--pin")) {
|
||||
item.parent.removeTab(item.id, false, false, false);
|
||||
item.parent.removeTab(item.id, false, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -402,7 +402,7 @@ export const JSONToLayout = (app: App, isStart: boolean) => {
|
|||
const tabId = item.getAttribute("data-id");
|
||||
const tab = getInstanceById(tabId) as Tab;
|
||||
if (tab) {
|
||||
tab.parent.removeTab(tabId, false, false, false);
|
||||
tab.parent.removeTab(tabId, false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -643,10 +643,10 @@ export const newModelByInitData = (app: App, tab: Tab, json: any) => {
|
|||
model = new Editor({
|
||||
app,
|
||||
tab,
|
||||
rootId: json.rootId,
|
||||
blockId: json.blockId,
|
||||
mode: json.mode,
|
||||
action: typeof json.action === "string" ? [json.action] : json.action,
|
||||
scrollAttr: json.scrollAttr,
|
||||
});
|
||||
}
|
||||
return model;
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import {openDocHistory} from "../../history/doc";
|
|||
import {openNewWindowById} from "../../window/openNewWindow";
|
||||
import {genImportMenu} from "../../menus/navigation";
|
||||
import {transferBlockRef} from "../../menus/block";
|
||||
import {saveScroll} from "../scroll/saveScroll";
|
||||
|
||||
export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {
|
||||
hideTooltip();
|
||||
|
|
@ -204,6 +205,7 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {
|
|||
label: window.siyuan.languages.openByNewWindow,
|
||||
icon: "iconOpenWindow",
|
||||
click() {
|
||||
saveScroll(protyle);
|
||||
openNewWindowById(protyle.block.rootID);
|
||||
}
|
||||
}).element);
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ import {insertHTML} from "./util/insertHTML";
|
|||
import {avRender} from "./render/av/render";
|
||||
import {focusBlock, getEditorRange} from "./util/selection";
|
||||
import {hasClosestBlock} from "./util/hasClosest";
|
||||
import {setStorageVal} from "./util/compatibility";
|
||||
|
||||
export class Protyle {
|
||||
|
||||
|
|
@ -196,7 +197,7 @@ export class Protyle {
|
|||
setEmpty(app);
|
||||
/// #else
|
||||
if (this.protyle.model) {
|
||||
this.protyle.model.parent.parent.removeTab(this.protyle.model.parent.id, false, false);
|
||||
this.protyle.model.parent.parent.removeTab(this.protyle.model.parent.id, false);
|
||||
}
|
||||
/// #endif
|
||||
}
|
||||
|
|
@ -207,9 +208,11 @@ export class Protyle {
|
|||
setEmpty(app);
|
||||
/// #else
|
||||
if (this.protyle.model) {
|
||||
this.protyle.model.parent.parent.removeTab(this.protyle.model.parent.id, false, false);
|
||||
this.protyle.model.parent.parent.removeTab(this.protyle.model.parent.id, false);
|
||||
}
|
||||
/// #endif
|
||||
delete window.siyuan.storage[Constants.LOCAL_FILEPOSITION][this.protyle.block.rootID];
|
||||
setStorageVal(Constants.LOCAL_FILEPOSITION, window.siyuan.storage[Constants.LOCAL_FILEPOSITION]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -225,10 +228,10 @@ export class Protyle {
|
|||
removeLoading(this.protyle);
|
||||
return;
|
||||
}
|
||||
if (options.scrollAttr) {
|
||||
if (options.rootId) {
|
||||
getDocByScroll({
|
||||
protyle: this.protyle,
|
||||
scrollAttr: options.scrollAttr,
|
||||
scrollAttr: window.siyuan.storage[Constants.LOCAL_FILEPOSITION][options.rootId],
|
||||
mergedOptions,
|
||||
cb: () => {
|
||||
this.afterOnGet(mergedOptions);
|
||||
|
|
@ -245,19 +248,10 @@ export class Protyle {
|
|||
this.getDoc(mergedOptions);
|
||||
return;
|
||||
}
|
||||
let scrollObj;
|
||||
if (response.data.ial.scroll) {
|
||||
try {
|
||||
scrollObj = JSON.parse(response.data.ial.scroll.replace(/"/g, '"'));
|
||||
} catch (e) {
|
||||
scrollObj = undefined;
|
||||
}
|
||||
}
|
||||
if (scrollObj) {
|
||||
scrollObj.rootId = response.data.rootID;
|
||||
if (window.siyuan.storage[Constants.LOCAL_FILEPOSITION][response.data.rootID]) {
|
||||
getDocByScroll({
|
||||
protyle: this.protyle,
|
||||
scrollAttr: scrollObj,
|
||||
scrollAttr: window.siyuan.storage[Constants.LOCAL_FILEPOSITION][response.data.rootID],
|
||||
mergedOptions,
|
||||
cb: () => {
|
||||
this.afterOnGet(mergedOptions);
|
||||
|
|
|
|||
|
|
@ -39,8 +39,8 @@ export const saveScroll = (protyle: IProtyle, getObject = false) => {
|
|||
if (getObject) {
|
||||
return attr;
|
||||
}
|
||||
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]);
|
||||
window.siyuan.storage[Constants.LOCAL_FILEPOSITION][protyle.block.rootID] = attr;
|
||||
setStorageVal(Constants.LOCAL_FILEPOSITION, window.siyuan.storage[Constants.LOCAL_FILEPOSITION]);
|
||||
};
|
||||
|
||||
export const getDocByScroll = (options: {
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ export const onGet = (options: {
|
|||
if (options.data.code === 1) {
|
||||
// 其他报错
|
||||
if (options.protyle.model) {
|
||||
options.protyle.model.parent.parent.removeTab(options.protyle.model.parent.id, false, false);
|
||||
options.protyle.model.parent.parent.removeTab(options.protyle.model.parent.id, false);
|
||||
} else {
|
||||
options.protyle.element.innerHTML = `<div class="ft__smaller ft__secondary b3-form__space--small" contenteditable="false">${window.siyuan.languages.refExpired}</div>`;
|
||||
}
|
||||
|
|
|
|||
2
app/src/types/protyle.d.ts
vendored
2
app/src/types/protyle.d.ts
vendored
|
|
@ -393,8 +393,8 @@ interface IOptions {
|
|||
action?: string[],
|
||||
mode?: TEditorMode,
|
||||
blockId: string
|
||||
rootId?: string
|
||||
key?: string
|
||||
scrollAttr?: IScrollAttr
|
||||
defId?: string
|
||||
render?: {
|
||||
background?: boolean
|
||||
|
|
|
|||
|
|
@ -53,12 +53,6 @@ export const openNewWindowById = (id: string, options: windowOptions = {}) => {
|
|||
}
|
||||
};
|
||||
if (response.data.rootID === id) {
|
||||
fetchPost("/api/attr/getBlockAttrs", {id}, (attrResponse) => {
|
||||
if (attrResponse.data.scroll) {
|
||||
json.children.scrollAttr = JSON.parse(attrResponse.data.scroll);
|
||||
// 历史数据兼容
|
||||
json.children.scrollAttr.rootId = response.data.rootID;
|
||||
}
|
||||
/// #if !BROWSER
|
||||
ipcRenderer.send(Constants.SIYUAN_OPEN_WINDOW, {
|
||||
position: options.position,
|
||||
|
|
@ -67,12 +61,8 @@ export const openNewWindowById = (id: string, options: windowOptions = {}) => {
|
|||
url: `${window.location.protocol}//${window.location.host}/stage/build/app/window.html?v=${Constants.SIYUAN_VERSION}&json=${encodeURIComponent(JSON.stringify(json))}`
|
||||
});
|
||||
/// #endif
|
||||
});
|
||||
} else {
|
||||
json.children.action = Constants.CB_GET_ALL;
|
||||
json.children.scrollAttr = {
|
||||
zoomInId: id,
|
||||
};
|
||||
/// #if !BROWSER
|
||||
ipcRenderer.send(Constants.SIYUAN_OPEN_WINDOW, {
|
||||
position: options.position,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue