This commit is contained in:
parent
65dc60a9fe
commit
0daed2d12a
12 changed files with 81 additions and 116 deletions
|
@ -1044,7 +1044,7 @@ const editKeydown = (event: KeyboardEvent) => {
|
|||
return false;
|
||||
}
|
||||
if (matchHotKey(window.siyuan.config.keymap.editor.general.refresh.custom, event)) {
|
||||
reloadProtyle(protyle);
|
||||
reloadProtyle(protyle, true);
|
||||
event.preventDefault();
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -334,7 +334,7 @@ export const editor = {
|
|||
}
|
||||
window.siyuan.config.editor = editorData;
|
||||
getAllModels().editor.forEach((item) => {
|
||||
reloadProtyle(item.editor.protyle);
|
||||
reloadProtyle(item.editor.protyle, false);
|
||||
setPadding(item.editor.protyle);
|
||||
if (window.siyuan.config.editor.fullWidth) {
|
||||
item.editor.protyle.contentElement.setAttribute("data-fullwidth", "true");
|
||||
|
|
|
@ -36,7 +36,7 @@ export const reloadSync = (data: { upsertRootIDs: string[], removeRootIDs: strin
|
|||
if (data.removeRootIDs.includes(window.siyuan.mobile.popEditor.protyle.block.rootID)) {
|
||||
hideElements(["dialog"]);
|
||||
} else {
|
||||
reloadProtyle(window.siyuan.mobile.popEditor.protyle);
|
||||
reloadProtyle(window.siyuan.mobile.popEditor.protyle, false);
|
||||
window.siyuan.mobile.popEditor.protyle.breadcrumb.render(window.siyuan.mobile.popEditor.protyle, true);
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ export const reloadSync = (data: { upsertRootIDs: string[], removeRootIDs: strin
|
|||
if (data.removeRootIDs.includes(window.siyuan.mobile.editor.protyle.block.rootID)) {
|
||||
setEmpty();
|
||||
} else {
|
||||
reloadProtyle(window.siyuan.mobile.editor.protyle);
|
||||
reloadProtyle(window.siyuan.mobile.editor.protyle, false);
|
||||
fetchPost("/api/block/getDocInfo", {
|
||||
id: window.siyuan.mobile.editor.protyle.block.rootID
|
||||
}, (response) => {
|
||||
|
@ -59,7 +59,7 @@ export const reloadSync = (data: { upsertRootIDs: string[], removeRootIDs: strin
|
|||
const allModels = getAllModels();
|
||||
allModels.editor.forEach(item => {
|
||||
if (data.upsertRootIDs.includes(item.editor.protyle.block.rootID)) {
|
||||
reloadProtyle(item.editor.protyle);
|
||||
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);
|
||||
|
|
|
@ -59,7 +59,7 @@ const replace = (element: Element, config: ISearchOption, isAll: boolean) => {
|
|||
if (ids.length > 1) {
|
||||
return;
|
||||
}
|
||||
reloadProtyle(window.siyuan.mobile.editor.protyle);
|
||||
reloadProtyle(window.siyuan.mobile.editor.protyle, false);
|
||||
|
||||
if (currentLiElement.nextElementSibling) {
|
||||
currentLiElement.nextElementSibling.classList.add("b3-list-item--focus");
|
||||
|
|
|
@ -40,7 +40,7 @@ const setEditor = (modelMainElement: Element) => {
|
|||
window.siyuan.config.editor.historyRetentionDays = parseInt((modelMainElement.querySelector("#historyRetentionDays") as HTMLInputElement).value);
|
||||
fetchPost("/api/setting/setEditor", window.siyuan.config.editor, response => {
|
||||
window.siyuan.config.editor = response.data;
|
||||
reloadProtyle(window.siyuan.mobile.editor.protyle);
|
||||
reloadProtyle(window.siyuan.mobile.editor.protyle, false);
|
||||
setInlineStyle();
|
||||
});
|
||||
};
|
||||
|
|
|
@ -18,11 +18,11 @@ export const netImg2LocalAssets = (protyle: IProtyle) => {
|
|||
id: protyle.block.rootID
|
||||
}, () => {
|
||||
/// #if MOBILE
|
||||
reloadProtyle(protyle);
|
||||
reloadProtyle(protyle, false);
|
||||
/// #else
|
||||
getAllModels().editor.forEach(item => {
|
||||
if (item.editor.protyle.block.rootID === protyle.block.rootID) {
|
||||
reloadProtyle(item.editor.protyle)
|
||||
reloadProtyle(item.editor.protyle, item.editor.protyle.element.isSameNode(protyle.element));
|
||||
}
|
||||
});
|
||||
/// #endif
|
||||
|
|
|
@ -245,11 +245,11 @@ export class Breadcrumb {
|
|||
id: protyle.block.rootID
|
||||
}, () => {
|
||||
/// #if MOBILE
|
||||
reloadProtyle(protyle);
|
||||
reloadProtyle(protyle, false);
|
||||
/// #else
|
||||
getAllModels().editor.forEach(item => {
|
||||
if (item.editor.protyle.block.rootID === protyle.block.rootID) {
|
||||
reloadProtyle(item.editor.protyle);
|
||||
reloadProtyle(item.editor.protyle, item.editor.protyle.element.isSameNode(protyle.element));
|
||||
}
|
||||
});
|
||||
/// #endif
|
||||
|
@ -304,7 +304,7 @@ export class Breadcrumb {
|
|||
accelerator: window.siyuan.config.keymap.editor.general.refresh.custom,
|
||||
label: window.siyuan.languages.refresh,
|
||||
click: () => {
|
||||
reloadProtyle(protyle);
|
||||
reloadProtyle(protyle, !isMobile());
|
||||
}
|
||||
}).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
|
|
|
@ -27,6 +27,7 @@ import {reloadProtyle} from "./util/reload";
|
|||
import {renderBacklink} from "./wysiwyg/renderBacklink";
|
||||
import {setEmpty} from "../mobile/util/setEmpty";
|
||||
import {resize} from "./util/resize";
|
||||
import {getDocByScroll} from "./scroll/saveScroll";
|
||||
|
||||
export class Protyle {
|
||||
|
||||
|
@ -111,7 +112,7 @@ export class Protyle {
|
|||
onGet(getResponse, this.protyle);
|
||||
});
|
||||
} else {
|
||||
reloadProtyle(this.protyle);
|
||||
reloadProtyle(this.protyle, false);
|
||||
}
|
||||
/// #if !MOBILE
|
||||
if (data.cmd === "heading2doc") {
|
||||
|
@ -206,14 +207,28 @@ export class Protyle {
|
|||
scrollObj = undefined;
|
||||
}
|
||||
if (scrollObj) {
|
||||
this.getDocByScrollData(scrollObj, mergedOptions);
|
||||
getDocByScroll({
|
||||
protyle: this.protyle,
|
||||
scrollAttr: scrollObj,
|
||||
mergedOptions,
|
||||
cb: () => {
|
||||
this.afterOnGet(mergedOptions);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.getDoc(mergedOptions);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.getDocByScrollData(options.scrollAttr, mergedOptions);
|
||||
getDocByScroll({
|
||||
protyle: this.protyle,
|
||||
scrollAttr: options.scrollAttr,
|
||||
mergedOptions,
|
||||
cb: () => {
|
||||
this.afterOnGet(mergedOptions);
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
this.getDoc(mergedOptions);
|
||||
|
@ -236,27 +251,6 @@ export class Protyle {
|
|||
});
|
||||
}
|
||||
|
||||
private getDocByScrollData(scrollAttr: IScrollAttr, mergedOptions: IOptions) {
|
||||
if (scrollAttr.zoomInId) {
|
||||
fetchPost("/api/filetree/getDoc", {
|
||||
id: scrollAttr.zoomInId,
|
||||
size: Constants.SIZE_GET_MAX,
|
||||
}, response => {
|
||||
onGet(response, this.protyle, mergedOptions.action, scrollAttr);
|
||||
this.afterOnGet(mergedOptions);
|
||||
})
|
||||
return;
|
||||
}
|
||||
fetchPost("/api/filetree/getDoc", {
|
||||
id: scrollAttr.startId,
|
||||
startID: scrollAttr.startId,
|
||||
endID: scrollAttr.endId,
|
||||
}, response => {
|
||||
onGet(response, this.protyle, mergedOptions.action, scrollAttr);
|
||||
this.afterOnGet(mergedOptions);
|
||||
});
|
||||
}
|
||||
|
||||
private afterOnGet(mergedOptions: IOptions) {
|
||||
if (this.protyle.model) {
|
||||
/// #if !MOBILE
|
||||
|
|
|
@ -1,14 +1,8 @@
|
|||
import {hasClosestBlock} from "../util/hasClosest";
|
||||
import {focusByOffset, getSelectionOffset} from "../util/selection";
|
||||
import {fetchPost} from "../../util/fetch";
|
||||
import {zoomOut} from "../../menus/protyle";
|
||||
import {preventScroll} from "./preventScroll";
|
||||
import {pushBack} from "../../util/backForward";
|
||||
import {processRender} from "../util/processCode";
|
||||
import {highlightRender} from "../markdown/highlightRender";
|
||||
import {blockRender} from "../markdown/blockRender";
|
||||
import {disabledForeverProtyle, disabledProtyle, enableProtyle} from "../util/onGet";
|
||||
import {showMessage} from "../../dialog/message";
|
||||
import {onGet} from "../util/onGet";
|
||||
import {Constants} from "../../constants";
|
||||
|
||||
export const saveScroll = (protyle: IProtyle, getObject = false) => {
|
||||
if (!protyle.wysiwyg.element.firstElementChild || window.siyuan.config.readonly) {
|
||||
|
@ -49,66 +43,45 @@ export const saveScroll = (protyle: IProtyle, getObject = false) => {
|
|||
});
|
||||
};
|
||||
|
||||
export const restoreScroll = (protyle: IProtyle, scrollAttr: IScrollAttr) => {
|
||||
preventScroll(protyle);
|
||||
if (protyle.wysiwyg.element.firstElementChild.getAttribute("data-node-id") === scrollAttr.startId &&
|
||||
protyle.wysiwyg.element.lastElementChild.getAttribute("data-node-id") === scrollAttr.endId) {
|
||||
// 需等动画效果完毕,才能获得最大高度。否则尾部定位无法滚动到底部
|
||||
setTimeout(() => {
|
||||
protyle.contentElement.scrollTop = scrollAttr.scrollTop;
|
||||
}, 256);
|
||||
if (scrollAttr.focusId) {
|
||||
const range = focusByOffset(protyle.wysiwyg.element.querySelector(`[data-node-id="${scrollAttr.focusId}"]`), scrollAttr.focusStart, scrollAttr.focusEnd);
|
||||
/// #if !MOBILE
|
||||
pushBack(protyle, range || undefined);
|
||||
/// #endif
|
||||
export const getDocByScroll = (options: {
|
||||
protyle: IProtyle,
|
||||
scrollAttr: IScrollAttr,
|
||||
mergedOptions?: IOptions,
|
||||
cb?: () => void
|
||||
focus?: boolean
|
||||
}) => {
|
||||
let actions: string[] = []
|
||||
if (options.mergedOptions) {
|
||||
actions = options.mergedOptions.action
|
||||
} else {
|
||||
if (options.focus) {
|
||||
actions = [Constants.CB_GET_UNUNDO, Constants.CB_GET_FOCUS]
|
||||
} else {
|
||||
actions = [Constants.CB_GET_UNUNDO];
|
||||
}
|
||||
if (options.scrollAttr.zoomInId) {
|
||||
actions.push(Constants.CB_GET_ALL);
|
||||
}
|
||||
} else if (scrollAttr.zoomInId && protyle.block.id !== scrollAttr.zoomInId) {
|
||||
fetchPost("/api/block/checkBlockExist", {id: scrollAttr.zoomInId}, existResponse => {
|
||||
if (existResponse.data) {
|
||||
zoomOut(protyle, scrollAttr.zoomInId, undefined, true, () => {
|
||||
protyle.contentElement.scrollTop = scrollAttr.scrollTop;
|
||||
if (scrollAttr.focusId) {
|
||||
focusByOffset(protyle.wysiwyg.element.querySelector(`[data-node-id="${scrollAttr.focusId}"]`), scrollAttr.focusStart, scrollAttr.focusEnd);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} else if (!protyle.scroll.element.classList.contains("fn__none")) {
|
||||
fetchPost("/api/filetree/getDoc", {
|
||||
id: protyle.block.id,
|
||||
startID: scrollAttr.startId,
|
||||
endID: scrollAttr.endId,
|
||||
}, getResponse => {
|
||||
protyle.block.showAll = false;
|
||||
protyle.wysiwyg.element.innerHTML = getResponse.data.content;
|
||||
processRender(protyle.wysiwyg.element);
|
||||
highlightRender(protyle.wysiwyg.element);
|
||||
blockRender(protyle, protyle.wysiwyg.element);
|
||||
if (getResponse.data.isSyncing) {
|
||||
disabledForeverProtyle(protyle);
|
||||
} else {
|
||||
if (protyle.disabled) {
|
||||
disabledProtyle(protyle);
|
||||
} else {
|
||||
enableProtyle(protyle);
|
||||
}
|
||||
}
|
||||
protyle.contentElement.scrollTop = scrollAttr.scrollTop;
|
||||
if (scrollAttr.focusId) {
|
||||
const range = focusByOffset(protyle.wysiwyg.element.querySelector(`[data-node-id="${scrollAttr.focusId}"]`), scrollAttr.focusStart, scrollAttr.focusEnd);
|
||||
/// #if !MOBILE
|
||||
pushBack(protyle, range || undefined);
|
||||
/// #endif
|
||||
}
|
||||
// 使用动态滚动条定位到最后一个块,重启后无法触发滚动事件,需要再次更新 index
|
||||
protyle.scroll.updateIndex(protyle, scrollAttr.startId);
|
||||
// https://github.com/siyuan-note/siyuan/issues/8224
|
||||
if (protyle.wysiwyg.element.clientHeight - parseInt(protyle.wysiwyg.element.style.paddingBottom) < protyle.contentElement.clientHeight) {
|
||||
showMessage(window.siyuan.languages.scrollGetMore);
|
||||
}
|
||||
});
|
||||
} else if (scrollAttr.scrollTop) {
|
||||
protyle.contentElement.scrollTop = scrollAttr.scrollTop;
|
||||
}
|
||||
if (options.scrollAttr.zoomInId) {
|
||||
fetchPost("/api/filetree/getDoc", {
|
||||
id: options.scrollAttr.zoomInId,
|
||||
size: Constants.SIZE_GET_MAX,
|
||||
}, response => {
|
||||
onGet(response, options.protyle, actions, options.scrollAttr);
|
||||
if (options.cb) {
|
||||
options.cb()
|
||||
}
|
||||
});
|
||||
}
|
||||
fetchPost("/api/filetree/getDoc", {
|
||||
id: options.scrollAttr.startId,
|
||||
startID: options.scrollAttr.startId,
|
||||
endID: options.scrollAttr.endId,
|
||||
}, response => {
|
||||
onGet(response, options.protyle, actions, options.scrollAttr);
|
||||
if (options.cb) {
|
||||
options.cb()
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
import {addLoading} from "../ui/initUI";
|
||||
import {fetchPost} from "../../util/fetch";
|
||||
import {Constants} from "../../constants";
|
||||
import {onGet} from "./onGet";
|
||||
import {saveScroll} from "../scroll/saveScroll";
|
||||
import {getDocByScroll, saveScroll} from "../scroll/saveScroll";
|
||||
import {renderBacklink} from "../wysiwyg/renderBacklink";
|
||||
import {hasClosestByClassName} from "./hasClosest";
|
||||
import {preventScroll} from "../scroll/preventScroll";
|
||||
|
||||
export const reloadProtyle = (protyle: IProtyle) => {
|
||||
export const reloadProtyle = (protyle: IProtyle, focus: boolean) => {
|
||||
if (window.siyuan.config.editor.displayBookmarkIcon) {
|
||||
protyle.wysiwyg.element.classList.add("protyle-wysiwyg--attr");
|
||||
} else {
|
||||
|
@ -38,12 +37,11 @@ export const reloadProtyle = (protyle: IProtyle) => {
|
|||
});
|
||||
}
|
||||
} else {
|
||||
fetchPost("/api/filetree/getDoc", {
|
||||
id: protyle.block.showAll ? protyle.block.id : protyle.block.rootID,
|
||||
mode: 0,
|
||||
size: protyle.block.showAll ? Constants.SIZE_GET_MAX : window.siyuan.config.editor.dynamicLoadBlocks,
|
||||
}, getResponse => {
|
||||
onGet(getResponse, protyle, protyle.block.showAll ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS], saveScroll(protyle, true), true);
|
||||
preventScroll(protyle);
|
||||
getDocByScroll({
|
||||
protyle,
|
||||
focus,
|
||||
scrollAttr: saveScroll(protyle, true)
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
@ -647,7 +647,7 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, focus: b
|
|||
return;
|
||||
}
|
||||
if (operation.action === "append") {
|
||||
reloadProtyle(protyle);
|
||||
reloadProtyle(protyle, false);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -961,7 +961,7 @@ const replace = (element: Element, config: ISearchOption, edit: Protyle, isAll:
|
|||
}
|
||||
getAllModels().editor.forEach(item => {
|
||||
if (rootIds[0] === item.editor.protyle.block.rootID) {
|
||||
reloadProtyle(item.editor.protyle);
|
||||
reloadProtyle(item.editor.protyle, false);
|
||||
}
|
||||
});
|
||||
if (currentList.nextElementSibling) {
|
||||
|
|
Loading…
Add table
Reference in a new issue