diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.ts index f11634e46..b5a4649cc 100644 --- a/app/src/protyle/gutter/index.ts +++ b/app/src/protyle/gutter/index.ts @@ -38,6 +38,7 @@ import {appearanceMenu} from "../toolbar/Font"; import {setPosition} from "../../util/setPosition"; import {avRender} from "../render/av/render"; import {emitOpenMenu} from "../../plugin/EventBus"; +import {resizeAV} from "../util/resize"; export class Gutter { public element: HTMLElement; @@ -710,12 +711,7 @@ export class Gutter { if (!isMobile()) { appearanceElement.lastElementChild.classList.add("b3-menu__submenu--row"); } - selectsElement.find((item) => { - if (!item.classList.contains("NodeAttributeView")) { - this.genAlign(selectsElement, protyle); - return true; - } - }); + this.genAlign(selectsElement, protyle); this.genWidths(selectsElement, protyle); window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element); window.siyuan.menus.menu.append(new MenuItem({ @@ -1515,9 +1511,7 @@ export class Gutter { if (!isMobile()) { appearanceElement.lastElementChild.classList.add("b3-menu__submenu--row"); } - if (type !== "NodeAttributeView") { - this.genAlign([nodeElement], protyle); - } + this.genAlign([nodeElement], protyle); this.genWidths([nodeElement], protyle); } window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element); @@ -1621,7 +1615,10 @@ export class Gutter { accelerator: window.siyuan.config.keymap.editor.general.alignLeft.custom, click: () => { this.genClick(nodeElements, protyle, (e: HTMLElement) => { - if (!e.classList.contains("NodeAttributeView")) { + if (e.classList.contains("av")) { + e.style.margin = "" + resizeAV(e); + } else { e.style.textAlign = "left"; } }); @@ -1632,7 +1629,10 @@ export class Gutter { accelerator: window.siyuan.config.keymap.editor.general.alignCenter.custom, click: () => { this.genClick(nodeElements, protyle, (e: HTMLElement) => { - if (!e.classList.contains("NodeAttributeView")) { + if (e.classList.contains("av")) { + e.style.margin = "0 auto"; + resizeAV(e); + } else { e.style.textAlign = "center"; } }); @@ -1643,7 +1643,10 @@ export class Gutter { accelerator: window.siyuan.config.keymap.editor.general.alignRight.custom, click: () => { this.genClick(nodeElements, protyle, (e: HTMLElement) => { - if (!e.classList.contains("NodeAttributeView")) { + if (e.classList.contains("av")) { + e.style.margin = "0 0 0 auto"; + resizeAV(e); + } else { e.style.textAlign = "right"; } }); @@ -1653,9 +1656,7 @@ export class Gutter { icon: "iconMenu", click: () => { this.genClick(nodeElements, protyle, (e: HTMLElement) => { - if (!e.classList.contains("NodeAttributeView")) { - e.style.textAlign = "justify"; - } + e.style.textAlign = "justify"; }); } }, { @@ -1665,9 +1666,7 @@ export class Gutter { icon: "iconLtr", click: () => { this.genClick(nodeElements, protyle, (e: HTMLElement) => { - if (!e.classList.contains("NodeAttributeView")) { - e.style.direction = "ltr"; - } + e.style.direction = "ltr"; }); } }, { @@ -1675,7 +1674,7 @@ export class Gutter { icon: "iconRtl", click: () => { this.genClick(nodeElements, protyle, (e: HTMLElement) => { - if (!e.classList.contains("NodeAttributeView")) { + if (!e.classList.contains("av")) { e.style.direction = "rtl"; } }); @@ -1687,8 +1686,13 @@ export class Gutter { icon: "iconTrashcan", click: () => { this.genClick(nodeElements, protyle, (e: HTMLElement) => { - e.style.textAlign = ""; - e.style.direction = ""; + if (e.classList.contains("av")) { + e.style.margin = ""; + resizeAV(e); + } else { + e.style.textAlign = ""; + e.style.direction = ""; + } }); } }] @@ -1704,6 +1708,7 @@ export class Gutter { this.genClick(nodeElements, protyle, (e: HTMLElement) => { e.style.width = item; e.style.flex = "none"; + resizeAV(e); }); } }); @@ -1743,12 +1748,13 @@ export class Gutter { }); }); rangeElement.addEventListener("change", () => { - nodeElements.forEach((e) => { + nodeElements.forEach((e: HTMLElement) => { operations.push({ action: "update", id: e.getAttribute("data-node-id"), data: e.outerHTML }); + resizeAV(e); }); transaction(protyle, operations, undoOperations); window.siyuan.menus.menu.remove(); @@ -1765,6 +1771,7 @@ export class Gutter { if (e.style.width) { e.style.width = ""; e.style.flex = ""; + resizeAV(e); } }); } diff --git a/app/src/protyle/render/av/render.ts b/app/src/protyle/render/av/render.ts index 6b1cefa03..234344896 100644 --- a/app/src/protyle/render/av/render.ts +++ b/app/src/protyle/render/av/render.ts @@ -5,6 +5,7 @@ import {getCalcValue} from "./cell"; import * as dayjs from "dayjs"; import {unicode2Emoji} from "../../../emoji"; import {focusBlock} from "../../util/selection"; +import {resizeAV} from "../../util/resize"; export const avRender = (element: Element, protyle: IProtyle, cb?: () => void) => { let avElements: Element[] = []; @@ -169,12 +170,9 @@ ${cell.color ? `color:${cell.color};` : ""}">${text}`; ${item.name} `; }); - const setWidth = e.style.width.endsWith("%"); - const paddingLeft = setWidth ? "" : e.parentElement.style.paddingLeft; - const paddingRight = setWidth ? "" : e.parentElement.style.paddingRight; setTimeout(() => { e.firstElementChild.outerHTML = `