diff --git a/packages/excalidraw/actions/actionFontSize.ts b/packages/excalidraw/actions/actionFontSize.ts index b0ee3fbff..84fa176fa 100644 --- a/packages/excalidraw/actions/actionFontSize.ts +++ b/packages/excalidraw/actions/actionFontSize.ts @@ -1,10 +1,37 @@ +import { newElementWith } from ".."; +import { isTextElement, redrawTextBoundingBox } from "../element"; import { ExcalidrawElement, ExcalidrawTextElement } from "../element/types"; import { KEYS } from "../keys"; import { AppClassProperties, AppState } from "../types"; +import { changeProperty } from "./actionProperties"; import { register } from "./register"; const FONT_SIZE_RELATIVE_INCREASE_STEP = 0.1; +const offsetElementAfterFontResize = ( + prevElement: ExcalidrawTextElement, + nextElement: ExcalidrawTextElement, +) => { + if (isBoundToContainer(nextElement)) { + return nextElement; + } + return mutateElement( + nextElement, + { + x: + prevElement.textAlign === "left" + ? prevElement.x + : prevElement.x + + (prevElement.width - nextElement.width) / + (prevElement.textAlign === "center" ? 2 : 1), + // centering vertically is non-standard, but for Excalidraw I think + // it makes sense + y: prevElement.y + (prevElement.height - nextElement.height) / 2, + }, + false, + ); +}; + const changeFontSize = ( elements: readonly ExcalidrawElement[], appState: AppState, diff --git a/packages/excalidraw/actions/actionProperties.tsx b/packages/excalidraw/actions/actionProperties.tsx index 9fee07e17..cbf5dc86f 100644 --- a/packages/excalidraw/actions/actionProperties.tsx +++ b/packages/excalidraw/actions/actionProperties.tsx @@ -1,4 +1,4 @@ -import { AppClassProperties, AppState, Primitive } from "../types"; +import { AppState, Primitive } from "../types"; import { DEFAULT_ELEMENT_BACKGROUND_COLOR_PALETTE, DEFAULT_ELEMENT_BACKGROUND_PICKS, @@ -83,7 +83,6 @@ import { VerticalAlign, } from "../element/types"; import { getLanguage, t } from "../i18n"; -import { KEYS } from "../keys"; import { randomInteger } from "../random"; import { canHaveArrowheads, @@ -159,30 +158,6 @@ export const getFormValue = function ( return ret; }; -const offsetElementAfterFontResize = ( - prevElement: ExcalidrawTextElement, - nextElement: ExcalidrawTextElement, -) => { - if (isBoundToContainer(nextElement)) { - return nextElement; - } - return mutateElement( - nextElement, - { - x: - prevElement.textAlign === "left" - ? prevElement.x - : prevElement.x + - (prevElement.width - nextElement.width) / - (prevElement.textAlign === "center" ? 2 : 1), - // centering vertically is non-standard, but for Excalidraw I think - // it makes sense - y: prevElement.y + (prevElement.height - nextElement.height) / 2, - }, - false, - ); -}; - // ----------------------------------------------------------------------------- export const actionChangeStrokeColor = register({