Commit 2d66b649 by ramdayalmunda

simple left and right arrow fixed

parent bae5be2c
...@@ -46,6 +46,8 @@ var ADocEditor = function (customConfig) { ...@@ -46,6 +46,8 @@ var ADocEditor = function (customConfig) {
style: { ...dataList[0].style, x: config.format.margin, y: config.format.margin + (3 * config.style.fontSize / 4) }, style: { ...dataList[0].style, x: config.format.margin, y: config.format.margin + (3 * config.style.fontSize / 4) },
} }
var pageList = [] var pageList = []
var focussedPage = null
var lastFocussedPage = null
var isRendering = false var isRendering = false
function initialize() { function initialize() {
config = JSON.parse(JSON.stringify(defaultConfig)) config = JSON.parse(JSON.stringify(defaultConfig))
...@@ -195,7 +197,7 @@ var ADocEditor = function (customConfig) { ...@@ -195,7 +197,7 @@ var ADocEditor = function (customConfig) {
calculateTextSizeAndPosition() calculateTextSizeAndPosition()
renderLines() renderLines()
caretData.previousCaret = null caretData.previousCaret = null
renderCaret() renderCaret(true)
function calculateTextSizeAndPosition() { function calculateTextSizeAndPosition() {
...@@ -306,7 +308,7 @@ var ADocEditor = function (customConfig) { ...@@ -306,7 +308,7 @@ var ADocEditor = function (customConfig) {
return return
} }
function renderCaret() { function renderCaret(toLoop) {
clearTimeout(caretData.timeout) clearTimeout(caretData.timeout)
let ctx = pageList[0].el.getContext('2d', { willReadFrequently: true }) let ctx = pageList[0].el.getContext('2d', { willReadFrequently: true })
ctx.save() ctx.save()
...@@ -331,7 +333,7 @@ var ADocEditor = function (customConfig) { ...@@ -331,7 +333,7 @@ var ADocEditor = function (customConfig) {
} }
} }
let width = height/8 let width = height/10
const imageData = ctx.getImageData(x, y, width, height); const imageData = ctx.getImageData(x, y, width, height);
const data = imageData.data; const data = imageData.data;
caretData.previousCaret = { imageData: structuredClone(imageData), x, y } caretData.previousCaret = { imageData: structuredClone(imageData), x, y }
...@@ -349,9 +351,11 @@ var ADocEditor = function (customConfig) { ...@@ -349,9 +351,11 @@ var ADocEditor = function (customConfig) {
} }
ctx.restore() ctx.restore()
if(toLoop){
caretData.timeout = setTimeout(() => { caretData.timeout = setTimeout(() => {
renderCaret() renderCaret(true)
}, caretData.timeoutDuration) }, caretData.timeoutDuration)
}
return return
} }
function getCharacterWidth(char, style) { function getCharacterWidth(char, style) {
...@@ -425,12 +429,34 @@ var ADocEditor = function (customConfig) { ...@@ -425,12 +429,34 @@ var ADocEditor = function (customConfig) {
caretData.activeData = dataObj caretData.activeData = dataObj
dataList.push(dataObj) dataList.push(dataObj)
} }
else if (e.key.length == 1 && !e.ctrlKey && !e.metaKey) { else if (e.key.length == 1 && !e.ctrlKey && !e.metaKey) { // displayable text
// ***** DISPLAYABLE TEXT **** //
e.preventDefault() e.preventDefault()
caretData.activeData.plainContent = caretData.activeData.plainContent.slice(0, caretData.index) + e.key + caretData.activeData.plainContent.slice(caretData.index + 1) caretData.activeData.plainContent = caretData.activeData.plainContent.slice(0, caretData.index) + e.key + caretData.activeData.plainContent.slice(caretData.index)
caretData.activeData.formatedText.splice(caretData.index, 0, caretData.style) caretData.activeData.formatedText.splice(caretData.index, 0, caretData.style)
++caretData.index ++caretData.index
} }
else if (e.key=='ArrowLeft'){
console.log('Left')
if (caretData.index){
--caretData.index
console.log('move')
}
}
else if (e.key=='ArrowRight'){
console.log('Right')
if (caretData.index<caretData.activeData.plainContent.length){
console.log('move')
++caretData.index
}
}
else if (e.key=='ArrowUp'){
console.log('Up')
}
else if (e.key=='ArrowDown'){
console.log('Down')
}
caretData.blink = false caretData.blink = false
caretData.previousCaret = null caretData.previousCaret = null
reRenderCanvas(dataList) reRenderCanvas(dataList)
...@@ -439,10 +465,15 @@ var ADocEditor = function (customConfig) { ...@@ -439,10 +465,15 @@ var ADocEditor = function (customConfig) {
// console.log('mouse down') // console.log('mouse down')
} }
function onFocusHandler(e) { function onFocusHandler(e) {
focussedPage = e.target
lastFocussedPage = e.target
reRenderCanvas() reRenderCanvas()
} }
function onBlurHandler(e) { function onBlurHandler(e) {
// console.log('blur') // console.log('blur')
caretData.blink = true
focussedPage = null
renderCaret()
} }
} }
......
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