Commit 5ce24a3b by ramdayalmunda

wrapping long words

parent e1d0ff89
......@@ -225,7 +225,6 @@ var ADocEditor = function (customConfig) {
renderCaret(true)
function calculateTextSizeAndPosition() {
let d = 0, c = 0;
function getLineObj() {
......@@ -257,21 +256,28 @@ var ADocEditor = function (customConfig) {
maxLineWidth -= tabWidth
lineObj.dataType = dataBlock.type
let wordEndIndex = 0; // this stores the index of the word which can fit in the line;
let tempWordWidth = 0
for (c = 0; c < dataBlock.plainContent.length; c++) {
let style = dataBlock?.formatedText?.[c]
if (/\s/.test(dataBlock.plainContent[c])) {
wordEndIndex = c
lineObj.charEndIndex = c
tempWordWidth = 0
}
let charWidth = getCharacterWidth(dataBlock.plainContent[c], style)
dataBlock.formatedText[c] = {
...config.style,
...style,
width: charWidth
}
if (tempLineWidth + charWidth > maxLineWidth) {
if (tempLineWidth + charWidth > maxLineWidth){
// cannot add this// new line should be added//
i = wordEndIndex;
if (tempWordWidth+charWidth>=maxLineWidth){
wordEndIndex = c
lineObj.charEndIndex = c
tempWordWidth = 0
}
lineObj.plainContent = dataBlock.plainContent.slice(lineObj.charStartIndex, lineObj.charEndIndex + 1)
lines.push(lineObj)
lineObj = new getLineObj()
......@@ -282,10 +288,15 @@ var ADocEditor = function (customConfig) {
lineObj.listIndex = dataBlock.listIndex
if (dataBlock.type==1) lineObj.tabCount = dataBlock.tabCount
else lineObj.tabCount = 0
lineObj.charStartIndex = i + 1
lineObj.charEndIndex = i + 1
tempLineWidth = 0
} else tempLineWidth += charWidth
lineObj.charStartIndex = wordEndIndex + 1
lineObj.charEndIndex = wordEndIndex + 1
tempLineWidth = tempWordWidth
}
else{
tempLineWidth += charWidth
tempWordWidth += charWidth
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment