Vanessa 2023-12-31 11:13:05 +08:00
parent fc5f24658d
commit 2e69b019e0
8 changed files with 22 additions and 35 deletions

View file

@ -111,7 +111,11 @@ export class Wnd {
this.renderTabList(target);
break;
} else if (target.tagName === "LI" && target.getAttribute("data-id") && !pdfIsLoading(this.element)) {
if (target.classList.contains("item--focus")) {
this.switchTab(target, true, true, false, false);
} else {
this.switchTab(target, true);
}
break;
}
target = target.parentElement;
@ -701,9 +705,6 @@ export class Wnd {
item.model.beforeDestroy();
}
}
if (item.model instanceof Editor) {
saveScroll(item.model.editor.protyle);
}
if (this.children.length === 1) {
this.destroyModel(this.children[0].model);
this.children = [];
@ -754,7 +755,7 @@ export class Wnd {
}
});
if (latestHeadElement && !closeAll) {
this.switchTab(latestHeadElement, true, true, false);
this.switchTab(latestHeadElement, true, true, false, false);
this.showHeading();
}
}

View file

@ -96,7 +96,6 @@ export class Layout {
});
}
addResize(child);
resizeTabs();
// https://ld246.com/article/1669858316295
if (this.direction === "tb") {
child.element.style.minHeight = "64px";

View file

@ -235,7 +235,6 @@ 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,

View file

@ -206,7 +206,6 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {
label: window.siyuan.languages.openByNewWindow,
icon: "iconOpenWindow",
click() {
saveScroll(protyle);
openNewWindowById(protyle.block.rootID);
}
}).element);

View file

@ -6,7 +6,7 @@ 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) {
if (!protyle.wysiwyg.element.firstElementChild || window.siyuan.config.readonly || protyle.element.classList.contains("fn__none")) {
// 报错或者空白页面
return undefined;
}

View file

@ -391,14 +391,15 @@ const focusElementById = (protyle: IProtyle, action: string[], scrollAttr?: IScr
}
/// #endif
}
if (scrollAttr && typeof scrollAttr.scrollTop === "number") {
const hasScrollTop = scrollAttr && typeof scrollAttr.scrollTop === "number"
if (hasScrollTop) {
protyle.contentElement.scrollTop = scrollAttr.scrollTop;
}
if (action.includes(Constants.CB_GET_FOCUS) || action.includes(Constants.CB_GET_HL) || action.includes(Constants.CB_GET_FOCUSFIRST)) {
const contentRect = protyle.contentElement.getBoundingClientRect();
const focusRect = focusElement.getBoundingClientRect();
if (contentRect.top > focusRect.top || contentRect.bottom < focusRect.bottom) {
scrollCenter(protyle, focusElement);
scrollCenter(protyle, focusElement, !hasScrollTop);
}
} else {
protyle.observerLoad?.disconnect();
@ -406,14 +407,14 @@ const focusElementById = (protyle: IProtyle, action: string[], scrollAttr?: IScr
}
// 加强定位
protyle.observerLoad = new ResizeObserver(() => {
if (scrollAttr && typeof scrollAttr.scrollTop === "number") {
if (hasScrollTop) {
protyle.contentElement.scrollTop = scrollAttr.scrollTop;
}
if (action.includes(Constants.CB_GET_FOCUS) || action.includes(Constants.CB_GET_HL) || action.includes(Constants.CB_GET_FOCUSFIRST)) {
const contentRect = protyle.contentElement.getBoundingClientRect();
const focusRect = focusElement.getBoundingClientRect();
if (contentRect.top > focusRect.top || contentRect.bottom < focusRect.bottom) {
scrollCenter(protyle, focusElement);
scrollCenter(protyle, focusElement, !hasScrollTop);
}
}
});

View file

@ -39,7 +39,7 @@ export const highlightById = (protyle: IProtyle, id: string, top = false) => {
};
export const scrollCenter = (protyle: IProtyle, nodeElement?: Element, top = false, behavior: ScrollBehavior = "auto") => {
if (!top && getSelection().rangeCount > 0 && hasClosestBlock(getSelection().getRangeAt(0).startContainer)) {
if (!protyle.disabled && !top && getSelection().rangeCount > 0 && hasClosestBlock(getSelection().getRangeAt(0).startContainer)) {
const editorElement = protyle.contentElement;
const cursorTop = getSelectionPosition(editorElement).top - editorElement.getBoundingClientRect().top;
let top = 0;

View file

@ -50,10 +50,9 @@ export const openNewWindowById = (id: string, options: windowOptions = {}) => {
rootId: response.data.rootID,
mode: "wysiwyg",
instance: "Editor",
action: response.data.rootID === id ? Constants.CB_GET_SCROLL : Constants.CB_GET_ALL
}
};
if (response.data.rootID === id) {
json.children.action = Constants.CB_GET_SCROLL;
/// #if !BROWSER
ipcRenderer.send(Constants.SIYUAN_OPEN_WINDOW, {
position: options.position,
@ -62,17 +61,6 @@ 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;
/// #if !BROWSER
ipcRenderer.send(Constants.SIYUAN_OPEN_WINDOW, {
position: options.position,
width: options.width,
height: options.height,
url: `${window.location.protocol}//${window.location.host}/stage/build/app/window.html?v=${Constants.SIYUAN_VERSION}&json=${encodeURIComponent(JSON.stringify(json))}`
});
/// #endif
}
});
};