Virtual whiteboard for sketching hand-drawn like diagrams
fix: Reduce padding to 5px for bounded text (#4530)
Aakansha Doshi5c67329be6bc
diff --git a/src/constants.ts b/src/constants.tsindex dfa579d2f1..38fd622285 100644--- a/src/constants.ts+++ b/src/constants.ts@@ -182,4 +182,4 @@ export const VERSIONS = {excalidrawLibrary: 2,} as const;-export const BOUND_TEXT_PADDING = 30;+export const BOUND_TEXT_PADDING = 5;diff --git a/src/element/textElement.test.ts b/src/element/textElement.test.tsindex 3c08b279f8..56bc7f6fb6 100644--- a/src/element/textElement.test.ts+++ b/src/element/textElement.test.ts@@ -9,14 +9,14 @@ describe("Test wrapText", () => {[{desc: "break all words when width of each word is less than container width",- width: 140,+ width: 90,res: `Hellowhatsup`,},{desc: "break all characters when width of each character is less than container width",- width: 75,+ width: 25,res: `Hel@@ -33,7 +33,7 @@ p`,{desc: "break words as per the width",- width: 200,+ width: 150,res: `Hello whatsup`,},@@ -56,14 +56,14 @@ whats up`;[{desc: "break all words when width of each word is less than container width",- width: 140,+ width: 90,res: `Hellowhatsup`,},{desc: "break all characters when width of each character is less than container width",- width: 75,+ width: 25,res: `Hel@@ -80,7 +80,7 @@ p`,{desc: "break words as per the width",- width: 200,+ width: 150,res: `Hellowhats up`,},@@ -103,7 +103,7 @@ whats up`,[{desc: "fit characters of long string as per container width",- width: 220,+ width: 170,res: `hellolongtextthisiswhatsupwithyouIamtypingggg@@ -114,19 +114,19 @@ break it now`,{desc: "fit characters of long string as per container width and break words as per the width",- width: 180,+ width: 130,res: `hellolongtextthisiswhatsupwithyouIamtypingggggandtyping-gg break it+gg break itnow`,},{desc: "fit the long text when container width is greater than text length and move the rest to next line",- width: 650,+ width: 600,res: `hellolongtextthisiswhatsupwithyouIamtypingggggandtypingggbreak it now`,},diff --git a/src/element/textElement.ts b/src/element/textElement.tsindex e6bd6193d5..d1f598ed7b 100644--- a/src/element/textElement.ts+++ b/src/element/textElement.ts@@ -22,7 +22,6 @@ export const redrawTextBoundingBox = (? container.width - BOUND_TEXT_PADDING * 2: undefined;let text = element.originalText;-// Call wrapText only when updating text properties// By clicking on the containerif (container && !isTextElement(appState.editingElement)) {@@ -112,20 +111,12 @@ export const handleBindTextResize = (let containerHeight = element.height;let nextBaseLine = textElement.baseline;if (transformHandleType !== "n" && transformHandleType !== "s") {- let minCharWidthTillNow = 0;if (text) {- minCharWidthTillNow = getMinCharWidth(getFontString(textElement));- // check if the diff has exceeded min char width needed- const diff = Math.abs(- element.width - textElement.width + BOUND_TEXT_PADDING * 2,+ text = wrapText(+ textElement.originalText,+ getFontString(textElement),+ element.width,);- if (diff >= minCharWidthTillNow) {- text = wrapText(- textElement.originalText,- getFontString(textElement),- element.width,- );- }}const dimensions = measureText(@@ -293,7 +284,7 @@ export const wrapText = (}}// push current line if appending space exceeds max width- if (currentLineWidthTillNow + spaceWidth > maxWidth) {+ if (currentLineWidthTillNow + spaceWidth >= maxWidth) {lines.push(currentLine);currentLine = "";currentLineWidthTillNow = 0;@@ -321,8 +312,15 @@ export const wrapText = (}index++;currentLine += `${word} `;- }+ // Push the word if appending space exceeds max width+ if (currentLineWidthTillNow + spaceWidth >= maxWidth) {+ lines.push(currentLine.slice(0, -1));+ currentLine = "";+ currentLineWidthTillNow = 0;+ break;+ }+ }if (currentLineWidthTillNow === maxWidth) {currentLine = "";currentLineWidthTillNow = 0;