diff --git a/app/src/config/editor.ts b/app/src/config/editor.ts index ec57380f3..dfd45a557 100644 --- a/app/src/config/editor.ts +++ b/app/src/config/editor.ts @@ -345,7 +345,11 @@ export const editor = { getAllModels().editor.forEach((item) => { reloadProtyle(item.editor.protyle, false); setPadding(item.editor.protyle); - if (window.siyuan.config.editor.fullWidth) { + let isFullWidth = item.editor.protyle.wysiwyg.element.getAttribute("custom-sy-fullwidth"); + if (!isFullWidth) { + isFullWidth = window.siyuan.config.editor.fullWidth ? "true" : "false"; + } + if (isFullWidth === "true") { item.editor.protyle.contentElement.setAttribute("data-fullwidth", "true"); } else { item.editor.protyle.contentElement.removeAttribute("data-fullwidth"); diff --git a/app/src/menus/commonMenuItem.ts b/app/src/menus/commonMenuItem.ts index 5efb163a0..896f5375e 100644 --- a/app/src/menus/commonMenuItem.ts +++ b/app/src/menus/commonMenuItem.ts @@ -155,7 +155,7 @@ export const openFileAttr = (attrs: IObject, focusName = "bookmark") => { let hasAV = false; const range = getSelection().rangeCount > 0 ? getSelection().getRangeAt(0) : null; Object.keys(attrs).forEach(item => { - if ("custom-riff-decks" === item) { + if ("custom-riff-decks" === item || item.startsWith("custom-sy-")) { return; } if (item === "custom-reminder-wechat") { diff --git a/app/src/protyle/breadcrumb/index.ts b/app/src/protyle/breadcrumb/index.ts index f3b815e1d..e9a87b1f7 100644 --- a/app/src/protyle/breadcrumb/index.ts +++ b/app/src/protyle/breadcrumb/index.ts @@ -324,17 +324,6 @@ export class Breadcrumb { } } if (!protyle.disabled) { - window.siyuan.menus.menu.append(new MenuItem({ - label: window.siyuan.languages.optimizeTypography, - accelerator: window.siyuan.config.keymap.editor.general.optimizeTypography.custom, - icon: "iconFormat", - click: () => { - hideElements(["toolbar"], protyle); - fetchPost("/api/format/autoSpace", { - id: protyle.block.rootID - }); - } - }).element); window.siyuan.menus.menu.append(new MenuItem({ label: window.siyuan.languages.netImg2LocalAsset, icon: "iconTransform", @@ -386,24 +375,30 @@ export class Breadcrumb { reloadProtyle(protyle, !isMobile()); } }).element); - window.siyuan.menus.menu.append(new MenuItem({ - icon: "iconTrashcan", - label: window.siyuan.languages.delete, - click: () => { - deleteFile(protyle.notebookId, protyle.path); - } - }).element); - if (!isMobile()) { + if (!protyle.disabled) { window.siyuan.menus.menu.append(new MenuItem({ - icon: protyle.element.className.includes("fullscreen") ? "iconFullscreenExit" : "iconFullscreen", - accelerator: window.siyuan.config.keymap.editor.general.fullscreen.custom, - label: window.siyuan.languages.fullscreen, + label: window.siyuan.languages.optimizeTypography, + accelerator: window.siyuan.config.keymap.editor.general.optimizeTypography.custom, + icon: "iconFormat", click: () => { - fullscreen(protyle.element); - setPadding(protyle); + hideElements(["toolbar"], protyle); + fetchPost("/api/format/autoSpace", { + id: protyle.block.rootID + }); } }).element); } + /// #if !MOBILE + window.siyuan.menus.menu.append(new MenuItem({ + icon: protyle.element.className.includes("fullscreen") ? "iconFullscreenExit" : "iconFullscreen", + accelerator: window.siyuan.config.keymap.editor.general.fullscreen.custom, + label: window.siyuan.languages.fullscreen, + click: () => { + fullscreen(protyle.element); + setPadding(protyle); + } + }).element); + /// #endif const editSubmenu: IMenu[] = [{ current: !protyle.contentElement.classList.contains("fn__none"), label: window.siyuan.languages.wysiwyg, @@ -428,8 +423,54 @@ export class Breadcrumb { type: "submenu", submenu: editSubmenu }).element); + /// #if !MOBILE + if (!protyle.disabled) { + const isCustomFullWidth = protyle.wysiwyg.element.getAttribute("custom-sy-fullwidth"); + window.siyuan.menus.menu.append(new MenuItem({ + label: window.siyuan.languages.fullWidth, + type: "submenu", + submenu: [{ + iconHTML: "", + current: isCustomFullWidth === "true", + label: window.siyuan.languages.use, + click() { + fetchPost("/api/attr/setBlockAttrs", { + id: protyle.block.rootID, + attrs: {"custom-sy-fullwidth": "true"} + }); + } + }, { + iconHTML: "", + current: isCustomFullWidth === "false", + label: window.siyuan.languages.close, + click() { + fetchPost("/api/attr/setBlockAttrs", { + id: protyle.block.rootID, + attrs: {"custom-sy-fullwidth": "false"} + }); + } + }, { + iconHTML: "", + current: !isCustomFullWidth, + label: window.siyuan.languages.default, + click() { + fetchPost("/api/attr/setBlockAttrs", { + id: protyle.block.rootID, + attrs: {"custom-sy-fullwidth": ""} + }); + } + }] + }).element); + } + /// #endif window.siyuan.menus.menu.append(exportMd(protyle.block.showAll ? protyle.block.id : protyle.block.rootID)); - + window.siyuan.menus.menu.append(new MenuItem({ + icon: "iconTrashcan", + label: window.siyuan.languages.delete, + click: () => { + deleteFile(protyle.notebookId, protyle.path); + } + }).element); if (protyle?.app?.plugins) { emitOpenMenu({ plugins: protyle.app.plugins, @@ -469,12 +510,12 @@ export class Breadcrumb { if (getSelection().rangeCount > 0) { range = getSelection().getRangeAt(0); if (!protyle.wysiwyg.element.isEqualNode(range.startContainer) && !protyle.wysiwyg.element.contains(range.startContainer)) { - if (protyle.element.id ==="searchPreview") { - // https://github.com/siyuan-note/siyuan/issues/8807 - blockElement = hasClosestBlock(protyle.wysiwyg.element.querySelector('[data-type="search-mark"]')) as Element; - } else { - blockElement = getNoContainerElement(protyle.wysiwyg.element.firstElementChild) || protyle.wysiwyg.element.firstElementChild; - } + if (protyle.element.id === "searchPreview") { + // https://github.com/siyuan-note/siyuan/issues/8807 + blockElement = hasClosestBlock(protyle.wysiwyg.element.querySelector('[data-type="search-mark"]')) as Element; + } else { + blockElement = getNoContainerElement(protyle.wysiwyg.element.firstElementChild) || protyle.wysiwyg.element.firstElementChild; + } } else { blockElement = hasClosestBlock(range.startContainer) as Element; } diff --git a/app/src/protyle/index.ts b/app/src/protyle/index.ts index 386f1bb7b..3307f58e6 100644 --- a/app/src/protyle/index.ts +++ b/app/src/protyle/index.ts @@ -204,7 +204,6 @@ export class Protyle { } } }); - setPadding(this.protyle); if (options.backlinkData) { this.protyle.block.rootID = options.blockId; renderBacklink(this.protyle, options.backlinkData); @@ -300,7 +299,7 @@ export class Protyle { }); /// #endif } - + setPadding(this.protyle); // 需等待 getDoc 完成后再执行,否则在无页签的时候 updatePanelByEditor 会执行2次 // 只能用 focusin,否则点击表格无法执行 this.protyle.wysiwyg.element.addEventListener("focusin", () => { diff --git a/app/src/protyle/ui/initUI.ts b/app/src/protyle/ui/initUI.ts index 1d90404e1..2ee354760 100644 --- a/app/src/protyle/ui/initUI.ts +++ b/app/src/protyle/ui/initUI.ts @@ -11,11 +11,6 @@ import {fetchPost} from "../../util/fetch"; export const initUI = (protyle: IProtyle) => { protyle.contentElement = document.createElement("div"); protyle.contentElement.className = "protyle-content"; - if (window.siyuan.config.editor.fullWidth) { - protyle.contentElement.setAttribute("data-fullwidth", "true"); - } else { - protyle.contentElement.removeAttribute("data-fullwidth"); - } if (protyle.options.render.background) { protyle.contentElement.appendChild(protyle.background.element); } @@ -129,7 +124,11 @@ export const setPadding = (protyle: IProtyle) => { let min24 = 24; if (!isMobile()) { let padding = (protyle.element.clientWidth - Constants.SIZE_EDITOR_WIDTH) / 2; - if (!window.siyuan.config.editor.fullWidth && padding > 96) { + let isFullWidth = protyle.wysiwyg.element.getAttribute("custom-sy-fullwidth"); + if (!isFullWidth) { + isFullWidth = window.siyuan.config.editor.fullWidth ? "true" : "false"; + } + if (isFullWidth === "false" && padding > 96) { if (padding > Constants.SIZE_EDITOR_WIDTH) { // 超宽屏调整 https://ld246.com/article/1668266637363 padding = protyle.element.clientWidth * .382 / 1.382; diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts index 61387be08..766a171e2 100644 --- a/app/src/protyle/wysiwyg/index.ts +++ b/app/src/protyle/wysiwyg/index.ts @@ -108,6 +108,15 @@ export class WYSIWYG { } public renderCustom(ial: IObject) { + let isFullWidth = ial["custom-sy-fullwidth"]; + if (!isFullWidth) { + isFullWidth = window.siyuan.config.editor.fullWidth ? "true" : "false"; + } + if (isFullWidth ==="true") { + this.element.parentElement.setAttribute("data-fullwidth", "true"); + } else { + this.element.parentElement.removeAttribute("data-fullwidth"); + } const ialKeys = Object.keys(ial); for (let i = 0; i < this.element.attributes.length; i++) { const oldKey = this.element.attributes[i].nodeName; diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.ts index 580fa3e73..1b9c9b4b0 100644 --- a/app/src/protyle/wysiwyg/transaction.ts +++ b/app/src/protyle/wysiwyg/transaction.ts @@ -18,6 +18,7 @@ import {hideElements} from "../ui/hideElements"; import {reloadProtyle} from "../util/reload"; import {countBlockWord} from "../../layout/status"; import {needLogin, needSubscribe} from "../../util/needSubscribe"; +import {setPadding} from "../ui/initUI"; const removeTopElement = (updateElement: Element, protyle: IProtyle) => { // 移动到其他文档中,该块需移除 @@ -424,7 +425,7 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, isUndo: if (operation.action === "delete") { if (updateElements.length > 0) { deleteBlock(updateElements, operation.id, protyle, isUndo); - } else if (isUndo){ + } else if (isUndo) { zoomOut({ protyle, id: protyle.block.rootID, @@ -503,6 +504,9 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, isUndo: protyle.title.element.querySelector(".protyle-attr").innerHTML = nodeAttrHTML; } protyle.wysiwyg.renderCustom(attrsResult); + if (data.new["custom-sy-fullwidth"] !== data.old["custom-sy-fullwidth"]) { + setPadding(protyle); + } if (data.new.icon !== data.old.icon) { /// #if MOBILE if (window.siyuan.mobile.editor.protyle.background.ial.icon !== data.new.icon) {