Commit 2767b644 by ramdayalmunda

caret position on multiple pages fixed

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