This commit is contained in:
parent
06cacf1311
commit
194a18fc95
7 changed files with 51 additions and 51 deletions
|
@ -3,6 +3,7 @@ import {setInlineStyle} from "../util/assets";
|
|||
import {fetchPost} from "../util/fetch";
|
||||
import {confirmDialog} from "../dialog/confirmDialog";
|
||||
import {setPadding} from "../protyle/ui/initUI";
|
||||
import {reloadProtyle} from "../protyle/util/reload";
|
||||
|
||||
export const editor = {
|
||||
element: undefined as Element,
|
||||
|
@ -201,7 +202,7 @@ export const editor = {
|
|||
onSetEditor: (editor: IEditor) => {
|
||||
window.siyuan.config.editor = editor;
|
||||
getAllModels().editor.forEach((item) => {
|
||||
item.editor.reload();
|
||||
reloadProtyle(item.editor.protyle)
|
||||
setPadding(item.editor.protyle);
|
||||
if (window.siyuan.config.editor.fullWidth) {
|
||||
item.editor.protyle.contentElement.setAttribute("data-fullwidth", "true");
|
||||
|
|
|
@ -2,6 +2,7 @@ import {closePanel} from "../util/closePanel";
|
|||
import {fetchPost} from "../../util/fetch";
|
||||
import {setInlineStyle} from "../../util/assets";
|
||||
import {genOptions} from "../../util/genOptions";
|
||||
import {reloadProtyle} from "../../protyle/util/reload";
|
||||
|
||||
export const initAppearance = (modelElement: HTMLElement, modelMainElement: HTMLElement) => {
|
||||
closePanel();
|
||||
|
@ -69,7 +70,7 @@ export const initAppearance = (modelElement: HTMLElement, modelMainElement: HTML
|
|||
emoji: window.siyuan.config.editor.emoji
|
||||
}, (response) => {
|
||||
window.siyuan.config.editor = response.data;
|
||||
window.siyuan.mobileEditor.reload();
|
||||
reloadProtyle(window.siyuan.mobileEditor.protyle);
|
||||
setInlineStyle();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -2,7 +2,7 @@ import {Constants} from "../constants";
|
|||
import {Hint} from "./hint";
|
||||
import {setLute} from "./markdown/setLute";
|
||||
import {Preview} from "./preview";
|
||||
import {addLoading, initUI, setPadding} from "./ui/initUI";
|
||||
import {initUI, setPadding} from "./ui/initUI";
|
||||
import {Undo} from "./undo";
|
||||
import {Upload} from "./upload";
|
||||
import {Options} from "./util/Options";
|
||||
|
@ -24,6 +24,7 @@ import {setPanelFocus} from "../layout/util";
|
|||
import {Background} from "./header/Background";
|
||||
import {getDisplayName} from "../util/pathName";
|
||||
import {onGet} from "./util/onGet";
|
||||
import {reloadProtyle} from "./util/reload";
|
||||
|
||||
class Protyle {
|
||||
|
||||
|
@ -93,24 +94,22 @@ class Protyle {
|
|||
case "heading2doc":
|
||||
case "li2doc":
|
||||
if (this.protyle.block.rootID === data.data.srcRootBlockID) {
|
||||
const scrollTop = this.protyle.contentElement.scrollTop;
|
||||
fetchPost("/api/filetree/getDoc", {
|
||||
id: this.protyle.block.id,
|
||||
size: Constants.SIZE_GET,
|
||||
}, getResponse => {
|
||||
onGet(getResponse, this.protyle);
|
||||
/// #if !MOBILE
|
||||
if (data.cmd === "heading2doc") {
|
||||
// 文档标题互转后,需更新大纲
|
||||
updatePanelByEditor(this.protyle, false, false, true);
|
||||
}
|
||||
/// #endif
|
||||
// 文档标题互转后,编辑区会跳转到开头 https://github.com/siyuan-note/siyuan/issues/2939
|
||||
setTimeout(() => {
|
||||
this.protyle.contentElement.scrollTop = scrollTop;
|
||||
this.protyle.scroll.lastScrollTop = scrollTop - 1;
|
||||
}, Constants.TIMEOUT_BLOCKLOAD);
|
||||
});
|
||||
if (this.protyle.block.showAll && data.cmd === "heading2doc") {
|
||||
fetchPost("/api/filetree/getDoc", {
|
||||
id: this.protyle.block.rootID,
|
||||
size: Constants.SIZE_GET,
|
||||
}, getResponse => {
|
||||
onGet(getResponse, this.protyle);
|
||||
})
|
||||
} else {
|
||||
reloadProtyle(this.protyle);
|
||||
}
|
||||
/// #if !MOBILE
|
||||
if (data.cmd === "heading2doc") {
|
||||
// 文档标题互转后,需更新大纲
|
||||
updatePanelByEditor(this.protyle, false, false, true);
|
||||
}
|
||||
/// #endif
|
||||
}
|
||||
break;
|
||||
case "rename":
|
||||
|
@ -206,23 +205,6 @@ class Protyle {
|
|||
}
|
||||
}
|
||||
|
||||
public reload() {
|
||||
if (window.siyuan.config.editor.displayBookmarkIcon) {
|
||||
this.protyle.wysiwyg.element.classList.add("protyle-wysiwyg--attr");
|
||||
} else {
|
||||
this.protyle.wysiwyg.element.classList.remove("protyle-wysiwyg--attr");
|
||||
}
|
||||
this.protyle.lute.SetProtyleMarkNetImg(window.siyuan.config.editor.displayNetImgMark);
|
||||
addLoading(this.protyle);
|
||||
fetchPost("/api/filetree/getDoc", {
|
||||
id: this.protyle.block.id,
|
||||
mode: 0,
|
||||
size: Constants.SIZE_GET,
|
||||
}, getResponse => {
|
||||
onGet(getResponse, this.protyle);
|
||||
});
|
||||
}
|
||||
|
||||
private init() {
|
||||
this.protyle.lute = setLute({
|
||||
emojiSite: this.protyle.options.hint.emojiPath,
|
||||
|
|
|
@ -97,5 +97,7 @@ export const restoreScroll = (protyle: IProtyle, scrollAttr: IScrollAttr) => {
|
|||
/// #endif
|
||||
}
|
||||
});
|
||||
} else if (scrollAttr.scrollTop) {
|
||||
protyle.contentElement.scrollTop = scrollAttr.scrollTop;
|
||||
}
|
||||
};
|
||||
|
|
22
app/src/protyle/util/reload.ts
Normal file
22
app/src/protyle/util/reload.ts
Normal file
|
@ -0,0 +1,22 @@
|
|||
import {addLoading} from "../ui/initUI";
|
||||
import {fetchPost} from "../../util/fetch";
|
||||
import {Constants} from "../../constants";
|
||||
import {onGet} from "./onGet";
|
||||
import {saveScroll} from "../scroll/saveScroll";
|
||||
|
||||
export const reloadProtyle = (protyle:IProtyle) => {
|
||||
if (window.siyuan.config.editor.displayBookmarkIcon) {
|
||||
protyle.wysiwyg.element.classList.add("protyle-wysiwyg--attr");
|
||||
} else {
|
||||
protyle.wysiwyg.element.classList.remove("protyle-wysiwyg--attr");
|
||||
}
|
||||
protyle.lute.SetProtyleMarkNetImg(window.siyuan.config.editor.displayNetImgMark);
|
||||
addLoading(protyle);
|
||||
fetchPost("/api/filetree/getDoc", {
|
||||
id: protyle.block.showAll ? protyle.block.id : protyle.block.rootID,
|
||||
mode: 0,
|
||||
size: protyle.block.showAll ? Constants.SIZE_GET_MAX : Constants.SIZE_GET,
|
||||
}, getResponse => {
|
||||
onGet(getResponse, protyle, protyle.block.showAll ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS], saveScroll(protyle, true), true);
|
||||
});
|
||||
}
|
|
@ -3,11 +3,9 @@ import {fetchPost} from "../../util/fetch";
|
|||
import {writeText} from "../util/compatibility";
|
||||
import {focusByOffset, getSelectionOffset} from "../util/selection";
|
||||
import {fullscreen, netImg2LocalAssets} from "../breadcrumb/action";
|
||||
import {addLoading, setPadding} from "../ui/initUI";
|
||||
import {Constants} from "../../constants";
|
||||
import {onGet} from "../util/onGet";
|
||||
import {setPadding} from "../ui/initUI";
|
||||
import {openBacklink, openGraph, openOutline} from "../../layout/dock/util";
|
||||
import {saveScroll} from "../scroll/saveScroll";
|
||||
import {reloadProtyle} from "../util/reload";
|
||||
|
||||
export const commonHotkey = (protyle: IProtyle, event: KeyboardEvent) => {
|
||||
const target = event.target as HTMLElement;
|
||||
|
@ -23,14 +21,7 @@ export const commonHotkey = (protyle: IProtyle, event: KeyboardEvent) => {
|
|||
}
|
||||
|
||||
if (matchHotKey(window.siyuan.config.keymap.editor.general.refresh.custom, event)) {
|
||||
addLoading(protyle);
|
||||
fetchPost("/api/filetree/getDoc", {
|
||||
id: protyle.block.showAll ? protyle.block.id : protyle.block.rootID,
|
||||
mode: 0,
|
||||
size: protyle.block.showAll ? Constants.SIZE_GET_MAX : Constants.SIZE_GET,
|
||||
}, getResponse => {
|
||||
onGet(getResponse, protyle, protyle.block.showAll ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS], saveScroll(protyle, true), true);
|
||||
});
|
||||
reloadProtyle(protyle);
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return true;
|
||||
|
|
|
@ -11,6 +11,7 @@ import {addLoading} from "../protyle/ui/initUI";
|
|||
import {getAllModels} from "../layout/getAll";
|
||||
import {showMessage} from "../dialog/message";
|
||||
import {focusByRange} from "../protyle/util/selection";
|
||||
import {reloadProtyle} from "../protyle/util/reload";
|
||||
|
||||
let protyle: Protyle;
|
||||
export const openSearch = async (hotkey: string, key?: string, notebookId?: string, searchPath?: string) => {
|
||||
|
@ -536,7 +537,7 @@ export const openSearch = async (hotkey: string, key?: string, notebookId?: stri
|
|||
}
|
||||
getAllModels().editor.forEach(item => {
|
||||
if (rootIds[0] === item.editor.protyle.block.rootID) {
|
||||
item.editor.reload();
|
||||
reloadProtyle(item.editor.protyle)
|
||||
}
|
||||
});
|
||||
if (!currentList.nextElementSibling && searchPanelElement.children[0]) {
|
||||
|
|
Loading…
Add table
Reference in a new issue