diff --git a/src/element/textElement.ts b/src/element/textElement.ts index 19bbcfbcb..2aa822bcb 100644 --- a/src/element/textElement.ts +++ b/src/element/textElement.ts @@ -83,6 +83,14 @@ export const redrawTextBoundingBox = ( const metrics = { width, height, baseline }; let coordY = textElement.y; let coordX = textElement.x; + // Maintain coordX for non left-aligned text in case the width has changed + if (!container) { + if (textElement.textAlign === TEXT_ALIGN.RIGHT) { + coordX += textElement.width - metrics.width; + } else if (textElement.textAlign === TEXT_ALIGN.CENTER) { + coordX += textElement.width / 2 - metrics.width / 2; + } + } // Resize container and vertically center align the text if (container) { if (!isArrowElement(container)) { diff --git a/src/element/textWysiwyg.tsx b/src/element/textWysiwyg.tsx index cbbf89248..fe0d8e6e0 100644 --- a/src/element/textWysiwyg.tsx +++ b/src/element/textWysiwyg.tsx @@ -170,7 +170,7 @@ export const textWysiwyg = ({ const width = eMetrics.width; // Set to element height by default since that's // what is going to be used for unbounded text - let textElementHeight = updatedTextElement.height; + let textElementHeight = Math.max(updatedTextElement.height, maxHeight); if (container && updatedTextElement.containerId) { if (isArrowElement(container)) { const boundTextCoords = diff --git a/src/packages/extensions/ts/mathjax/implementation.tsx b/src/packages/extensions/ts/mathjax/implementation.tsx index 75121d731..6392b6a62 100644 --- a/src/packages/extensions/ts/mathjax/implementation.tsx +++ b/src/packages/extensions/ts/mathjax/implementation.tsx @@ -356,6 +356,9 @@ const consumeMathNewlines = ( mathProps: MathProps, isMathJaxLoaded: boolean, ) => { + if (!isMathJaxLoaded) { + return text; + } const tempText = splitMath(text.replace(/\r\n?/g, "\n"), mathProps); if (mathProps.useTex || !mathProps.mathOnly) { for (let i = 0; i < tempText.length; i++) { @@ -472,7 +475,7 @@ const markupText = ( isMathJaxLoaded: boolean, ) => { const lines = consumeMathNewlines(text, mathProps, isMathJaxLoaded).split( - getMathNewline(mathProps), + isMathJaxLoaded ? getMathNewline(mathProps) : "\n", ); const markup = [] as Array[]; const aria = [] as Array[]; @@ -709,7 +712,7 @@ const renderMath = ( parentWidth?: number, ): string => { const mathLines = consumeMathNewlines(text, mathProps, isMathJaxLoaded).split( - getMathNewline(mathProps), + isMathJaxLoaded ? getMathNewline(mathProps) : "\n", ); const { markup, aria } = markupText(text, mathProps, isMathJaxLoaded); const metrics = getMetrics(markup, fontSize, mathProps, isMathJaxLoaded); @@ -1150,7 +1153,7 @@ const wrapMathElement = function (element, containerWidth, next) { const metrics = getMetrics(markup, fontSize, mathProps, isMathJaxLoaded); const lines = consumeMathNewlines(text, mathProps, isMathJaxLoaded).split( - "\n", + isMathJaxLoaded ? getMathNewline(mathProps) : "\n", ); const wrappedLines: string[] = []; const spaceWidth = getTextWidth(" ", font);