Commit 05f1f83f by ramdayalmunda

left right last char not reading fixed

parent cd8e544e
......@@ -166,11 +166,9 @@ var ADocEditor = function (customConfig) {
lines = []
for (let i = 0; i < dataList.length; i++) {
let canvas = canvasList[canvasIndex].el
calculateTextSizeAndPosition(canvasIndex, i)
}
renderTheLines()
console.log('render lines:', lines[0])
if (!caretData.blink && caretData.activeData) renderCaret()
......@@ -239,11 +237,6 @@ var ADocEditor = function (customConfig) {
tempLineWidth = 0
}
// counter++
// if (counter >= 500){
// console.log('was stuck', counter)
// break
// }
}
lineObj.plainContent = dataBlock.plainContent.slice(lineObj.charStartIndex, lineObj.charEndIndex)
// there is chance that the last line is not at the width// so we need to handle the last line separately
......@@ -306,13 +299,9 @@ var ADocEditor = function (customConfig) {
function renderCaret() {
let ctx = canvasList[caretData.canvasIndex].el.getContext('2d', { willReadFrequently: true })
ctx.save()
console.log( 'lines', lines)
console.log( 'dataSet', dataSet)
let activeDataIndex = dataSet.findIndex( item => item.id == caretData.activeData.id )
let activeLine = lines.find( (item, i) => {
console.log(i, 'line', item.dataSetIndex, activeDataIndex, '--',item.charEndIndex , caretData.index )
console.log(i+1, 'line+1', lines[i+1]?.dataSetIndex, activeDataIndex, '--',lines[i+1]?.charEndIndex , caretData.index )
if (item.dataSetIndex == activeDataIndex){
if (item.charEndIndex == -1) return true
if (item.charEndIndex>=caretData.index) return true
......@@ -322,9 +311,16 @@ var ADocEditor = function (customConfig) {
})
// handle left right on multiple pages
if (activeLine){
canvasList[ activeLine.canvasIndex ].el.focus()
caretData.canvasIndex = activeLine.canvasIndex
ctx.restore()
ctx = canvasList[activeLine.canvasIndex].el.getContext('2d', { willReadFrequently: true })
ctx.save()
}
console.log('activeLine', activeLine)
let characterData = dataSet[activeDataIndex].formatedText[ caretData.index ]
let rectX = characterData?.x,
......@@ -332,16 +328,12 @@ var ADocEditor = function (customConfig) {
rectWidth = 2,
rectHeight = 5 * activeLine.maxFontSize / 4;
if (!characterData && dataSet[activeDataIndex].formatedText?.[ caretData.index-1 ]){
console.log('handle X on the last char of the parapgraph')
rectX = dataSet[activeDataIndex].formatedText?.[ caretData.index-1 ]?.x+dataSet[activeDataIndex].formatedText?.[ caretData.index-1 ]?.width
}
if ( activeLine.charEndIndex == caretData.index ){
console.log('handle X on last char of the line')
rectX = dataSet[activeDataIndex].formatedText?.[ caretData.index-1 ]?.x+dataSet[activeDataIndex].formatedText?.[ caretData.index-1 ]?.width
}
if (!(rectX>0 || rectX==0)){ rectX = activeLine.x }
console.log('rectX:', rectX)
console.log('rectY:', rectY)
const imageData = ctx.getImageData(rectX, rectY, rectWidth, rectHeight);
const data = imageData.data;
......@@ -354,7 +346,6 @@ var ADocEditor = function (customConfig) {
// Alpha channel remains unchanged (data[i + 3])
ctx.putImageData(imageData, rectX, rectY);
}
console.log('caretData', caretData)
ctx.restore()
}
......
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