Commit 2767b644 by ramdayalmunda

caret position on multiple pages fixed

parent 76cb7969
......@@ -193,12 +193,11 @@ var ADocEditor = function (customConfig) {
}
dataList[i].style.canvasX = x
let canvas = canvasList[canvasIndex].el
canvas.setAttribute("tabIndex", -1)
calculateTextPositions(canvas, dataList[i])
x = 0;
if (dataList[i].id == caretData.activeData.id) {
caretData.canvasIndex = canvasIndex;
}
// if (dataList[i].id == caretData.activeData.id) {
// // caretData.canvasIndex = canvasIndex; // this was the issue;
// }
}
renderFormattedData()
if (!caretData.blink && caretData.activeData) renderCaret()
......@@ -324,7 +323,7 @@ var ADocEditor = function (customConfig) {
// to render caret
function renderCaret() {
console.log('caretCanvas',caretData.canvasIndex)
console.log('renderCaret',caretData.canvasIndex, caretData.index)
let ctx = canvasList[caretData.canvasIndex].el.getContext('2d', { willReadFrequently: true })
let activeTextData = caretData.activeData.formatedText[caretData.index - 1]
if (!activeTextData) activeTextData = caretData.activeData.style
......@@ -350,6 +349,7 @@ var ADocEditor = function (customConfig) {
function createCanvas() {
let canvas = document.createElement('canvas')
canvas.setAttribute("tabIndex", -1)
canvas.setAttribute('class', 'page')
canvas.setAttribute('id', `canvas_${++counter}`)
canvas.width = config.pageSetup.canvasWidth
......@@ -494,7 +494,6 @@ var ADocEditor = function (customConfig) {
}
function setCaretPosition(e) {
console.clear()
let rect = e.target.getBoundingClientRect()
let canvasIndex = canvasList.findIndex( item => item.el == e.target )
......@@ -539,15 +538,14 @@ var ADocEditor = function (customConfig) {
if (!dataSet[setIndex].plainContent.length){
charIndex = 0
}else{
console.log('after loop, ', dataSet[setIndex].formatedText[86])
for(let i=charIndex; (dataSet[setIndex].formatedText[i]?.canvasY && dataSet[setIndex].formatedText[i].canvasY == lineY);i++){
console.log('i', i)
let i=0
for(i=charIndex; (dataSet[setIndex].formatedText[i]?.canvasY && dataSet[setIndex].formatedText[i].canvasY == lineY);i++){
if(dataSet[setIndex].formatedText[i]?.canvasX >= position.x){
charIndex = i;
i++
break;
}
}
console.log('after loop')
charIndex = i-1
}
......@@ -555,7 +553,6 @@ var ADocEditor = function (customConfig) {
caretData.activeData = dataSet[setIndex];
caretData.index = charIndex;
caretData.canvasIndex = canvasIndex;
console.log("caretDatacanvasIndex:", caretData.canvasIndex)
caretData.blink = false
break;
}
......@@ -575,9 +572,9 @@ var ADocEditor = function (customConfig) {
charIndex++
}
console.log("final careCanvasIndex:", caretData.canvasIndex)
console.log("last line:", caretData.canvasIndex)
}
console.log('full break;')
console.log('full break;', caretData.canvasIndex, caretData.index)
......
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