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

View file

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

View file

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

View file

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

View file

@ -6,7 +6,7 @@ import {Constants} from "../../constants";
import {setStorageVal} from "../util/compatibility"; 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 || protyle.element.classList.contains("fn__none")) {
// 报错或者空白页面 // 报错或者空白页面
return undefined; return undefined;
} }

View file

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

View file

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