This commit is contained in:
Vanessa 2022-10-17 11:43:33 +08:00
parent c5e3a6ecf4
commit 31d699ae7e
5 changed files with 98 additions and 91 deletions

View file

@ -276,6 +276,7 @@ const setHTML = (options: { content: string, action?: string[], unScroll?: boole
/** 禁用编辑器 */
export const disabledProtyle = (protyle: IProtyle) => {
window.siyuan.menus.menu.remove();
hideElements(["gutter", "toolbar", "select", "hint", "util"], protyle);
protyle.disabled = true;
if (protyle.title) {
@ -283,6 +284,9 @@ export const disabledProtyle = (protyle: IProtyle) => {
titleElement.setAttribute("contenteditable", "false");
titleElement.style.userSelect = "text";
}
if (protyle.background) {
protyle.background.element.classList.remove("protyle-background--enable");
}
protyle.wysiwyg.element.style.userSelect = "text";
protyle.wysiwyg.element.setAttribute("contenteditable", "false");
protyle.wysiwyg.element.querySelectorAll('[contenteditable="true"][spellcheck="false"]').forEach(item => {
@ -294,16 +298,19 @@ export const disabledProtyle = (protyle: IProtyle) => {
export const enableProtyle = (protyle: IProtyle) => {
protyle.disabled = false;
if (navigator && navigator.maxTouchPoints > 1 && ["MacIntel", "iPhone"].includes(navigator.platform)) {
// iPhoneiPad 端输入 contenteditable 为 true 时会在块中间插入 span
// iPhoneiPad 端 protyle.wysiwyg.element contenteditable 为 true 时,输入会在块中间插入 span 导致保存失败 https://ld246.com/article/1643473862873/comment/1643813765839#comments
} else {
if (protyle.title) {
const titleElement = protyle.title.element.querySelector(".protyle-title__input") as HTMLElement;
titleElement.setAttribute("contenteditable", "true");
titleElement.style.userSelect = "";
}
protyle.wysiwyg.element.setAttribute("contenteditable", "true");
protyle.wysiwyg.element.style.userSelect = "";
}
if (protyle.title) {
const titleElement = protyle.title.element.querySelector(".protyle-title__input") as HTMLElement;
titleElement.setAttribute("contenteditable", "true");
titleElement.style.userSelect = "";
}
if (protyle.background) {
protyle.background.element.classList.add("protyle-background--enable");
}
protyle.wysiwyg.element.querySelectorAll('[contenteditable="false"][spellcheck="false"]').forEach(item => {
if (!hasClosestByClassName(item, "protyle-wysiwyg__embed")) {
item.setAttribute("contenteditable", "true");