mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-24 02:20:13 +01:00
This commit is contained in:
parent
05248d66be
commit
fb0c2e3d6a
7 changed files with 26 additions and 24 deletions
|
|
@ -351,6 +351,10 @@ 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({
|
||||||
|
|
@ -647,7 +651,7 @@ export const copyTab = (app: App, tab: Tab) => {
|
||||||
if (tab.model instanceof Editor) {
|
if (tab.model instanceof Editor) {
|
||||||
model = new Editor({
|
model = new Editor({
|
||||||
tab: newTab,
|
tab: newTab,
|
||||||
blockId: tab.model.editor.protyle.block.rootID,
|
blockId: tab.model.editor.protyle.block.id,
|
||||||
scrollAttr: saveScroll(tab.model.editor.protyle, true)
|
scrollAttr: saveScroll(tab.model.editor.protyle, true)
|
||||||
});
|
});
|
||||||
} else if (tab.model instanceof Asset) {
|
} else if (tab.model instanceof Asset) {
|
||||||
|
|
@ -708,9 +712,12 @@ export const copyTab = (app: App, tab: Tab) => {
|
||||||
}
|
}
|
||||||
} else if (!tab.model && tab.headElement) {
|
} else if (!tab.model && tab.headElement) {
|
||||||
const initData = JSON.parse(tab.headElement.getAttribute("data-initdata") || "{}");
|
const initData = JSON.parse(tab.headElement.getAttribute("data-initdata") || "{}");
|
||||||
|
if (initData.scrollAttr) {
|
||||||
|
initData.scrollAttr.rootId = initData.rootId;
|
||||||
|
}
|
||||||
model = new Editor({
|
model = new Editor({
|
||||||
tab: newTab,
|
tab: newTab,
|
||||||
blockId: initData.rootId || initData.blockId,
|
blockId: initData.blockId,
|
||||||
mode: initData.mode,
|
mode: initData.mode,
|
||||||
action: typeof initData.action === "string" ? [initData.action] : initData.action,
|
action: typeof initData.action === "string" ? [initData.action] : initData.action,
|
||||||
scrollAttr: initData.scrollAttr,
|
scrollAttr: initData.scrollAttr,
|
||||||
|
|
|
||||||
|
|
@ -218,6 +218,7 @@ export class Protyle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (scrollObj) {
|
if (scrollObj) {
|
||||||
|
scrollObj.rootId = response.data.rootID;
|
||||||
getDocByScroll({
|
getDocByScroll({
|
||||||
protyle: this.protyle,
|
protyle: this.protyle,
|
||||||
scrollAttr: scrollObj,
|
scrollAttr: scrollObj,
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ export const saveScroll = (protyle: IProtyle, getObject = false) => {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
const attr: IScrollAttr = {
|
const attr: IScrollAttr = {
|
||||||
|
rootId: protyle.block.rootID,
|
||||||
startId: protyle.wysiwyg.element.firstElementChild.getAttribute("data-node-id"),
|
startId: protyle.wysiwyg.element.firstElementChild.getAttribute("data-node-id"),
|
||||||
endId: protyle.wysiwyg.element.lastElementChild.getAttribute("data-node-id"),
|
endId: protyle.wysiwyg.element.lastElementChild.getAttribute("data-node-id"),
|
||||||
scrollTop: protyle.contentElement.scrollTop || parseInt(protyle.contentElement.getAttribute("data-scrolltop")) || 0,
|
scrollTop: protyle.contentElement.scrollTop || parseInt(protyle.contentElement.getAttribute("data-scrolltop")) || 0,
|
||||||
|
|
@ -59,23 +60,22 @@ export const getDocByScroll = (options: {
|
||||||
} else {
|
} else {
|
||||||
actions = [Constants.CB_GET_UNUNDO];
|
actions = [Constants.CB_GET_UNUNDO];
|
||||||
}
|
}
|
||||||
if (options.scrollAttr.zoomInId) {
|
|
||||||
actions.push(Constants.CB_GET_ALL);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (options.scrollAttr.zoomInId) {
|
if (options.scrollAttr.zoomInId) {
|
||||||
fetchPost("/api/filetree/getDoc", {
|
fetchPost("/api/filetree/getDoc", {
|
||||||
id: options.scrollAttr.zoomInId,
|
id: options.scrollAttr.zoomInId,
|
||||||
size: Constants.SIZE_GET_MAX,
|
size: Constants.SIZE_GET_MAX,
|
||||||
}, response => {
|
}, response => {
|
||||||
|
actions.push(Constants.CB_GET_ALL);
|
||||||
onGet(response, options.protyle, actions, options.scrollAttr);
|
onGet(response, options.protyle, actions, options.scrollAttr);
|
||||||
if (options.cb) {
|
if (options.cb) {
|
||||||
options.cb();
|
options.cb();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
fetchPost("/api/filetree/getDoc", {
|
fetchPost("/api/filetree/getDoc", {
|
||||||
id: options.mergedOptions.blockId,
|
id: options.mergedOptions?.blockId || options.protyle.block?.rootID || options.scrollAttr.startId,
|
||||||
startID: options.scrollAttr.startId,
|
startID: options.scrollAttr.startId,
|
||||||
endID: options.scrollAttr.endId,
|
endID: options.scrollAttr.endId,
|
||||||
}, response => {
|
}, response => {
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ export const onGet = (data: IWebSocketData, protyle: IProtyle, action: string[]
|
||||||
protyle.block.scroll = data.data.scroll;
|
protyle.block.scroll = data.data.scroll;
|
||||||
protyle.block.action = action;
|
protyle.block.action = action;
|
||||||
if (!action.includes(Constants.CB_GET_UNCHANGEID)) {
|
if (!action.includes(Constants.CB_GET_UNCHANGEID)) {
|
||||||
protyle.block.id = data.data.id;
|
protyle.block.id = data.data.id; // 非缩放情况时不一定是 rootID(搜索打开页签);缩放时必为缩放 id,否则需查看代码
|
||||||
protyle.scroll.lastScrollTop = 0;
|
protyle.scroll.lastScrollTop = 0;
|
||||||
protyle.contentElement.scrollTop = 0;
|
protyle.contentElement.scrollTop = 0;
|
||||||
protyle.wysiwyg.element.setAttribute("data-doc-type", data.data.type);
|
protyle.wysiwyg.element.setAttribute("data-doc-type", data.data.type);
|
||||||
|
|
@ -173,7 +173,7 @@ const setHTML = (options: {
|
||||||
}
|
}
|
||||||
/// #endif
|
/// #endif
|
||||||
} else {
|
} else {
|
||||||
focusElement(protyle, options);
|
focusElementById(protyle, options.action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!protyle.scroll.element.classList.contains("fn__none")) {
|
if (!protyle.scroll.element.classList.contains("fn__none")) {
|
||||||
|
|
@ -193,7 +193,7 @@ const setHTML = (options: {
|
||||||
}
|
}
|
||||||
/// #endif
|
/// #endif
|
||||||
} else if (options.action.includes(Constants.CB_GET_FOCUS)) {
|
} else if (options.action.includes(Constants.CB_GET_FOCUS)) {
|
||||||
focusElement(protyle, options);
|
focusElementById(protyle, options.action);
|
||||||
} else if (options.action.includes(Constants.CB_GET_FOCUSFIRST)) {
|
} else if (options.action.includes(Constants.CB_GET_FOCUSFIRST)) {
|
||||||
// settimeout 时间需短一点,否则定位后快速滚动无效
|
// settimeout 时间需短一点,否则定位后快速滚动无效
|
||||||
const headerHeight = protyle.wysiwyg.element.offsetTop - 16;
|
const headerHeight = protyle.wysiwyg.element.offsetTop - 16;
|
||||||
|
|
@ -322,13 +322,7 @@ export const enableProtyle = (protyle: IProtyle) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const focusElement = (protyle: IProtyle, options: {
|
const focusElementById = (protyle: IProtyle, action: string[]) => {
|
||||||
content: string,
|
|
||||||
action?: string[],
|
|
||||||
isSyncing: boolean,
|
|
||||||
expand: boolean,
|
|
||||||
scrollAttr?: IScrollAttr
|
|
||||||
}) => {
|
|
||||||
let focusElement: Element;
|
let focusElement: Element;
|
||||||
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${protyle.block.id}"]`)).find((item: HTMLElement) => {
|
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${protyle.block.id}"]`)).find((item: HTMLElement) => {
|
||||||
if (!hasClosestByAttribute(item, "data-type", "block-render", true)) {
|
if (!hasClosestByAttribute(item, "data-type", "block-render", true)) {
|
||||||
|
|
@ -343,7 +337,7 @@ const focusElement = (protyle: IProtyle, options: {
|
||||||
if (focusElement && !protyle.wysiwyg.element.firstElementChild.isSameNode(focusElement)) {
|
if (focusElement && !protyle.wysiwyg.element.firstElementChild.isSameNode(focusElement)) {
|
||||||
focusBlock(focusElement);
|
focusBlock(focusElement);
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
if (!options.action.includes(Constants.CB_GET_UNUNDO)) {
|
if (!action.includes(Constants.CB_GET_UNUNDO)) {
|
||||||
pushBack(protyle, undefined, focusElement);
|
pushBack(protyle, undefined, focusElement);
|
||||||
}
|
}
|
||||||
/// #endif
|
/// #endif
|
||||||
|
|
@ -355,7 +349,7 @@ const focusElement = (protyle: IProtyle, options: {
|
||||||
} else {
|
} else {
|
||||||
focusBlock(protyle.wysiwyg.element.firstElementChild);
|
focusBlock(protyle.wysiwyg.element.firstElementChild);
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
if (!options.action.includes(Constants.CB_GET_UNUNDO)) {
|
if (!action.includes(Constants.CB_GET_UNUNDO)) {
|
||||||
pushBack(protyle, undefined, protyle.wysiwyg.element.firstElementChild);
|
pushBack(protyle, undefined, protyle.wysiwyg.element.firstElementChild);
|
||||||
}
|
}
|
||||||
/// #endif
|
/// #endif
|
||||||
|
|
|
||||||
2
app/src/types/index.d.ts
vendored
2
app/src/types/index.d.ts
vendored
|
|
@ -242,6 +242,7 @@ interface ISiyuan {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IScrollAttr {
|
interface IScrollAttr {
|
||||||
|
rootId: string,
|
||||||
startId: string,
|
startId: string,
|
||||||
endId: string
|
endId: string
|
||||||
scrollTop: number,
|
scrollTop: number,
|
||||||
|
|
@ -269,6 +270,7 @@ interface IObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
declare interface ILayoutJSON extends ILayoutOptions {
|
declare interface ILayoutJSON extends ILayoutOptions {
|
||||||
|
scrollAttr?: IScrollAttr,
|
||||||
instance?: string,
|
instance?: string,
|
||||||
width?: string,
|
width?: string,
|
||||||
height?: string,
|
height?: string,
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@ const focusStack = async (stack: IBackStack) => {
|
||||||
docIcon: info.data.rootIcon,
|
docIcon: info.data.rootIcon,
|
||||||
callback(tab) {
|
callback(tab) {
|
||||||
const scrollAttr = saveScroll(stack.protyle, true);
|
const scrollAttr = saveScroll(stack.protyle, true);
|
||||||
|
scrollAttr.rootId = stack.protyle.block.rootID;
|
||||||
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;
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,8 @@ export const openNewWindowById = (id: string) => {
|
||||||
fetchPost("/api/attr/getBlockAttrs", {id}, (attrResponse) => {
|
fetchPost("/api/attr/getBlockAttrs", {id}, (attrResponse) => {
|
||||||
if (attrResponse.data.scroll) {
|
if (attrResponse.data.scroll) {
|
||||||
json.children.scrollAttr = JSON.parse(attrResponse.data.scroll);
|
json.children.scrollAttr = JSON.parse(attrResponse.data.scroll);
|
||||||
|
// 历史数据兼容
|
||||||
|
json.children.scrollAttr.rootId = response.data.rootID;
|
||||||
}
|
}
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER
|
||||||
ipcRenderer.send(Constants.SIYUAN_OPENWINDOW, {
|
ipcRenderer.send(Constants.SIYUAN_OPENWINDOW, {
|
||||||
|
|
@ -56,12 +58,7 @@ export const openNewWindowById = (id: string) => {
|
||||||
} else {
|
} else {
|
||||||
json.children.action = Constants.CB_GET_ALL;
|
json.children.action = Constants.CB_GET_ALL;
|
||||||
json.children.scrollAttr = {
|
json.children.scrollAttr = {
|
||||||
startId: id,
|
zoomInId: id,
|
||||||
endId: id,
|
|
||||||
scrollTop: 0,
|
|
||||||
focusId: id,
|
|
||||||
focusStart: 0,
|
|
||||||
focusEnd: 0
|
|
||||||
};
|
};
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER
|
||||||
ipcRenderer.send(Constants.SIYUAN_OPENWINDOW, {
|
ipcRenderer.send(Constants.SIYUAN_OPENWINDOW, {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue