Commit 5ce24a3b by ramdayalmunda

wrapping long words

parent e1d0ff89
...@@ -225,7 +225,6 @@ var ADocEditor = function (customConfig) { ...@@ -225,7 +225,6 @@ var ADocEditor = function (customConfig) {
renderCaret(true) renderCaret(true)
function calculateTextSizeAndPosition() { function calculateTextSizeAndPosition() {
let d = 0, c = 0; let d = 0, c = 0;
function getLineObj() { function getLineObj() {
...@@ -257,21 +256,28 @@ var ADocEditor = function (customConfig) { ...@@ -257,21 +256,28 @@ var ADocEditor = function (customConfig) {
maxLineWidth -= tabWidth maxLineWidth -= tabWidth
lineObj.dataType = dataBlock.type lineObj.dataType = dataBlock.type
let wordEndIndex = 0; // this stores the index of the word which can fit in the line; 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++) { for (c = 0; c < dataBlock.plainContent.length; c++) {
let style = dataBlock?.formatedText?.[c] let style = dataBlock?.formatedText?.[c]
if (/\s/.test(dataBlock.plainContent[c])) { if (/\s/.test(dataBlock.plainContent[c])) {
wordEndIndex = c wordEndIndex = c
lineObj.charEndIndex = c lineObj.charEndIndex = c
tempWordWidth = 0
} }
let charWidth = getCharacterWidth(dataBlock.plainContent[c], style) let charWidth = getCharacterWidth(dataBlock.plainContent[c], style)
dataBlock.formatedText[c] = { dataBlock.formatedText[c] = {
...config.style, ...config.style,
...style, ...style,
width: charWidth width: charWidth
} }
if (tempLineWidth + charWidth > maxLineWidth) { if (tempLineWidth + charWidth > maxLineWidth){
// cannot add this// new line should be added// // 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) lineObj.plainContent = dataBlock.plainContent.slice(lineObj.charStartIndex, lineObj.charEndIndex + 1)
lines.push(lineObj) lines.push(lineObj)
lineObj = new getLineObj() lineObj = new getLineObj()
...@@ -282,10 +288,15 @@ var ADocEditor = function (customConfig) { ...@@ -282,10 +288,15 @@ var ADocEditor = function (customConfig) {
lineObj.listIndex = dataBlock.listIndex lineObj.listIndex = dataBlock.listIndex
if (dataBlock.type==1) lineObj.tabCount = dataBlock.tabCount if (dataBlock.type==1) lineObj.tabCount = dataBlock.tabCount
else lineObj.tabCount = 0 else lineObj.tabCount = 0
lineObj.charStartIndex = i + 1 lineObj.charStartIndex = wordEndIndex + 1
lineObj.charEndIndex = i + 1 lineObj.charEndIndex = wordEndIndex + 1
tempLineWidth = 0 tempLineWidth = tempWordWidth
} else tempLineWidth += charWidth }
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