Commit bae5be2c by ramdayalmunda

caret position when typing fixed

parent 9b2648a1
......@@ -275,13 +275,12 @@ var ADocEditor = function (customConfig) {
}
function renderLines() {
console.log('render lines', lines)
let x = 0, y = config.format.margin*pxMmRatio;
for (let l = 0; l < lines.length; l++) {
let ctx = pageList[0].el.getContext('2d', { willReadFrequently: true })
console.log(lines[l])
x = config.format.margin*pxMmRatio
y = y + (lines[l].maxFontSize * pxMmRatio)
lines[l].y = y
ctx.save()
let setData = dataList[lines[l].dataIndex]
......@@ -311,7 +310,6 @@ var ADocEditor = function (customConfig) {
clearTimeout(caretData.timeout)
let ctx = pageList[0].el.getContext('2d', { willReadFrequently: true })
ctx.save()
if (caretData.previousCaret) {
ctx.putImageData(caretData.previousCaret.imageData, caretData.previousCaret.x, caretData.previousCaret.y);
caretData.previousCaret = null
......@@ -321,6 +319,18 @@ var ADocEditor = function (customConfig) {
let x = config.format.margin*pxMmRatio
let y = (config.format.margin)*pxMmRatio
let height = config.style.fontSize*pxMmRatio*5/4
let charData = caretData.activeData.formatedText[caretData.index-1]
if (charData){
x = charData.x+charData.width
y = charData.y-charData.fontSize*pxMmRatio
}else{
let dataIndex = dataList.findIndex( item => item.id == caretData.activeData.id )
let lineObj = lines.find( item => item.dataIndex==dataIndex && caretData.index>=item.charStartIndex)
if (lineObj){
y = lineObj.y-lineObj.maxFontSize*pxMmRatio
}
}
let width = height/8
const imageData = ctx.getImageData(x, y, width, height);
const data = imageData.data;
......@@ -345,7 +355,6 @@ var ADocEditor = function (customConfig) {
return
}
function getCharacterWidth(char, style) {
console.log('style', style)
let canvas = pageList[0].el
let ctx = canvas.getContext('2d', { willReadFrequently: true })
ctx.save()
......
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