MCPcopy Index your code
hub / github.com/OpenSignLabs/OpenSign / breakTextIntoLines

Function breakTextIntoLines

apps/OpenSign/src/constant/Utils.js:2373–2390  ·  view source on GitHub ↗
(textContent, width)

Source from the content-addressed store, hash-verified

2371 };
2372 // Function to break text into lines based on when user go next line on press enter button
2373 const breakTextIntoLines = (textContent, width) => {
2374 const finalLines = [];
2375 const paragraphs = textContent.split("\n"); // preserve user order
2376 for (const para of paragraphs) {
2377 const lineWidth = font.widthOfTextAtSize(para, fontSize);
2378 //checking string length to container width
2379 //if string length is less then container width it means user press enter button
2380 if (lineWidth <= width) {
2381 // user forced newline
2382 finalLines.push(para);
2383 } else {
2384 // auto wrap paragraph
2385 finalLines.push(...NewbreakTextIntoLines(para, width));
2386 }
2387 }
2388
2389 return finalLines;
2390 };
2391 //check if text content have `\n` string it means user press enter to go next line and handle condition
2392 //else auto adjust text content according to container width
2393 const lines = isNewOnEnterLineExist

Callers 1

embedWidgetsToDocFunction · 0.85

Calls 1

NewbreakTextIntoLinesFunction · 0.85

Tested by

no test coverage detected