mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-24 02:20:13 +01:00
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 {fetchPost} from "../util/fetch";
|
||||||
import {confirmDialog} from "../dialog/confirmDialog";
|
import {confirmDialog} from "../dialog/confirmDialog";
|
||||||
import {setPadding} from "../protyle/ui/initUI";
|
import {setPadding} from "../protyle/ui/initUI";
|
||||||
|
import {reloadProtyle} from "../protyle/util/reload";
|
||||||
|
|
||||||
export const editor = {
|
export const editor = {
|
||||||
element: undefined as Element,
|
element: undefined as Element,
|
||||||
|
|
@ -201,7 +202,7 @@ export const editor = {
|
||||||
onSetEditor: (editor: IEditor) => {
|
onSetEditor: (editor: IEditor) => {
|
||||||
window.siyuan.config.editor = editor;
|
window.siyuan.config.editor = editor;
|
||||||
getAllModels().editor.forEach((item) => {
|
getAllModels().editor.forEach((item) => {
|
||||||
item.editor.reload();
|
reloadProtyle(item.editor.protyle)
|
||||||
setPadding(item.editor.protyle);
|
setPadding(item.editor.protyle);
|
||||||
if (window.siyuan.config.editor.fullWidth) {
|
if (window.siyuan.config.editor.fullWidth) {
|
||||||
item.editor.protyle.contentElement.setAttribute("data-fullwidth", "true");
|
item.editor.protyle.contentElement.setAttribute("data-fullwidth", "true");
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import {closePanel} from "../util/closePanel";
|
||||||
import {fetchPost} from "../../util/fetch";
|
import {fetchPost} from "../../util/fetch";
|
||||||
import {setInlineStyle} from "../../util/assets";
|
import {setInlineStyle} from "../../util/assets";
|
||||||
import {genOptions} from "../../util/genOptions";
|
import {genOptions} from "../../util/genOptions";
|
||||||
|
import {reloadProtyle} from "../../protyle/util/reload";
|
||||||
|
|
||||||
export const initAppearance = (modelElement: HTMLElement, modelMainElement: HTMLElement) => {
|
export const initAppearance = (modelElement: HTMLElement, modelMainElement: HTMLElement) => {
|
||||||
closePanel();
|
closePanel();
|
||||||
|
|
@ -69,7 +70,7 @@ export const initAppearance = (modelElement: HTMLElement, modelMainElement: HTML
|
||||||
emoji: window.siyuan.config.editor.emoji
|
emoji: window.siyuan.config.editor.emoji
|
||||||
}, (response) => {
|
}, (response) => {
|
||||||
window.siyuan.config.editor = response.data;
|
window.siyuan.config.editor = response.data;
|
||||||
window.siyuan.mobileEditor.reload();
|
reloadProtyle(window.siyuan.mobileEditor.protyle);
|
||||||
setInlineStyle();
|
setInlineStyle();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import {Constants} from "../constants";
|
||||||
import {Hint} from "./hint";
|
import {Hint} from "./hint";
|
||||||
import {setLute} from "./markdown/setLute";
|
import {setLute} from "./markdown/setLute";
|
||||||
import {Preview} from "./preview";
|
import {Preview} from "./preview";
|
||||||
import {addLoading, initUI, setPadding} from "./ui/initUI";
|
import {initUI, setPadding} from "./ui/initUI";
|
||||||
import {Undo} from "./undo";
|
import {Undo} from "./undo";
|
||||||
import {Upload} from "./upload";
|
import {Upload} from "./upload";
|
||||||
import {Options} from "./util/Options";
|
import {Options} from "./util/Options";
|
||||||
|
|
@ -24,6 +24,7 @@ import {setPanelFocus} from "../layout/util";
|
||||||
import {Background} from "./header/Background";
|
import {Background} from "./header/Background";
|
||||||
import {getDisplayName} from "../util/pathName";
|
import {getDisplayName} from "../util/pathName";
|
||||||
import {onGet} from "./util/onGet";
|
import {onGet} from "./util/onGet";
|
||||||
|
import {reloadProtyle} from "./util/reload";
|
||||||
|
|
||||||
class Protyle {
|
class Protyle {
|
||||||
|
|
||||||
|
|
@ -93,24 +94,22 @@ class Protyle {
|
||||||
case "heading2doc":
|
case "heading2doc":
|
||||||
case "li2doc":
|
case "li2doc":
|
||||||
if (this.protyle.block.rootID === data.data.srcRootBlockID) {
|
if (this.protyle.block.rootID === data.data.srcRootBlockID) {
|
||||||
const scrollTop = this.protyle.contentElement.scrollTop;
|
if (this.protyle.block.showAll && data.cmd === "heading2doc") {
|
||||||
fetchPost("/api/filetree/getDoc", {
|
fetchPost("/api/filetree/getDoc", {
|
||||||
id: this.protyle.block.id,
|
id: this.protyle.block.rootID,
|
||||||
size: Constants.SIZE_GET,
|
size: Constants.SIZE_GET,
|
||||||
}, getResponse => {
|
}, getResponse => {
|
||||||
onGet(getResponse, this.protyle);
|
onGet(getResponse, this.protyle);
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
reloadProtyle(this.protyle);
|
||||||
|
}
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
if (data.cmd === "heading2doc") {
|
if (data.cmd === "heading2doc") {
|
||||||
// 文档标题互转后,需更新大纲
|
// 文档标题互转后,需更新大纲
|
||||||
updatePanelByEditor(this.protyle, false, false, true);
|
updatePanelByEditor(this.protyle, false, false, true);
|
||||||
}
|
}
|
||||||
/// #endif
|
/// #endif
|
||||||
// 文档标题互转后,编辑区会跳转到开头 https://github.com/siyuan-note/siyuan/issues/2939
|
|
||||||
setTimeout(() => {
|
|
||||||
this.protyle.contentElement.scrollTop = scrollTop;
|
|
||||||
this.protyle.scroll.lastScrollTop = scrollTop - 1;
|
|
||||||
}, Constants.TIMEOUT_BLOCKLOAD);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "rename":
|
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() {
|
private init() {
|
||||||
this.protyle.lute = setLute({
|
this.protyle.lute = setLute({
|
||||||
emojiSite: this.protyle.options.hint.emojiPath,
|
emojiSite: this.protyle.options.hint.emojiPath,
|
||||||
|
|
|
||||||
|
|
@ -97,5 +97,7 @@ export const restoreScroll = (protyle: IProtyle, scrollAttr: IScrollAttr) => {
|
||||||
/// #endif
|
/// #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 {writeText} from "../util/compatibility";
|
||||||
import {focusByOffset, getSelectionOffset} from "../util/selection";
|
import {focusByOffset, getSelectionOffset} from "../util/selection";
|
||||||
import {fullscreen, netImg2LocalAssets} from "../breadcrumb/action";
|
import {fullscreen, netImg2LocalAssets} from "../breadcrumb/action";
|
||||||
import {addLoading, setPadding} from "../ui/initUI";
|
import {setPadding} from "../ui/initUI";
|
||||||
import {Constants} from "../../constants";
|
|
||||||
import {onGet} from "../util/onGet";
|
|
||||||
import {openBacklink, openGraph, openOutline} from "../../layout/dock/util";
|
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) => {
|
export const commonHotkey = (protyle: IProtyle, event: KeyboardEvent) => {
|
||||||
const target = event.target as HTMLElement;
|
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)) {
|
if (matchHotKey(window.siyuan.config.keymap.editor.general.refresh.custom, event)) {
|
||||||
addLoading(protyle);
|
reloadProtyle(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);
|
|
||||||
});
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import {addLoading} from "../protyle/ui/initUI";
|
||||||
import {getAllModels} from "../layout/getAll";
|
import {getAllModels} from "../layout/getAll";
|
||||||
import {showMessage} from "../dialog/message";
|
import {showMessage} from "../dialog/message";
|
||||||
import {focusByRange} from "../protyle/util/selection";
|
import {focusByRange} from "../protyle/util/selection";
|
||||||
|
import {reloadProtyle} from "../protyle/util/reload";
|
||||||
|
|
||||||
let protyle: Protyle;
|
let protyle: Protyle;
|
||||||
export const openSearch = async (hotkey: string, key?: string, notebookId?: string, searchPath?: string) => {
|
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 => {
|
getAllModels().editor.forEach(item => {
|
||||||
if (rootIds[0] === item.editor.protyle.block.rootID) {
|
if (rootIds[0] === item.editor.protyle.block.rootID) {
|
||||||
item.editor.reload();
|
reloadProtyle(item.editor.protyle)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!currentList.nextElementSibling && searchPanelElement.children[0]) {
|
if (!currentList.nextElementSibling && searchPanelElement.children[0]) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue