Commit 2470d679 by ramdayalmunda

indentation handled

parent 8b4d6816
...@@ -253,7 +253,6 @@ var ADocEditor = function (customConfig) { ...@@ -253,7 +253,6 @@ var ADocEditor = function (customConfig) {
let tempLineWidth = 0; let tempLineWidth = 0;
let maxLineWidth = config.pageSetup.pxWidth - (config.format.margin * pxMmRatio * 2) let maxLineWidth = config.pageSetup.pxWidth - (config.format.margin * pxMmRatio * 2)
let tabWidth =( (dataBlock.type==1?1:0)+ dataBlock.tabCount)*config.format.tabWidth*pxMmRatio let tabWidth =( (dataBlock.type==1?1:0)+ dataBlock.tabCount)*config.format.tabWidth*pxMmRatio
console.log('tabWidth', tabWidth)
lineObj.tabWidth = tabWidth lineObj.tabWidth = tabWidth
maxLineWidth -= tabWidth maxLineWidth -= tabWidth
lineObj.dataType = dataBlock.type lineObj.dataType = dataBlock.type
...@@ -307,7 +306,6 @@ var ADocEditor = function (customConfig) { ...@@ -307,7 +306,6 @@ var ADocEditor = function (customConfig) {
let ctx = pageList[0].el.getContext('2d', { willReadFrequently: true }) let ctx = pageList[0].el.getContext('2d', { willReadFrequently: true })
x = config.format.margin * pxMmRatio x = config.format.margin * pxMmRatio
x += lines[l].tabWidth x += lines[l].tabWidth
console.log('line',l, lines[l])
y = y + (lines[l].maxFontSize * pxMmRatio) y = y + (lines[l].maxFontSize * pxMmRatio)
lines[l].y = y lines[l].y = y
ctx.save() ctx.save()
...@@ -356,7 +354,6 @@ var ADocEditor = function (customConfig) { ...@@ -356,7 +354,6 @@ var ADocEditor = function (customConfig) {
let dataIndex = dataList.findIndex(item => item.id == caretData.activeData.id) let dataIndex = dataList.findIndex(item => item.id == caretData.activeData.id)
let lineObj = lines.find(item => item.dataIndex == dataIndex && caretData.index >= item.charStartIndex) let lineObj = lines.find(item => item.dataIndex == dataIndex && caretData.index >= item.charStartIndex)
if (lineObj) { if (lineObj) {
console.log('line', lineObj)
x += lineObj.tabWidth x += lineObj.tabWidth
y = lineObj.y - lineObj.maxFontSize * pxMmRatio y = lineObj.y - lineObj.maxFontSize * pxMmRatio
} }
...@@ -364,7 +361,6 @@ var ADocEditor = function (customConfig) { ...@@ -364,7 +361,6 @@ var ADocEditor = function (customConfig) {
let width = height / 10 let width = height / 10
console.log(x,y,width,height)
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 }
...@@ -431,12 +427,14 @@ var ADocEditor = function (customConfig) { ...@@ -431,12 +427,14 @@ var ADocEditor = function (customConfig) {
} }
function keydownHandler(e) { function keydownHandler(e) {
if (e.key=='Tab'){
if (e.altKey) return
else if (e.key=='Tab'){
e.preventDefault() e.preventDefault()
caretData.activeData.tabCount += e.shiftKey?(-1):1 manageIndentation(e.shiftKey?-1:1)
caretData.activeData.tabCount = (caretData.activeData.tabCount<0)?0:(caretData.activeData.tabCount>5?5:caretData.activeData.tabCount) }else if ([']','['].includes(e.key) && e.ctrlKey){
manageIndentation( e.key=='['?-1:1 )
} }
if (e.altKey) return
else if (e.key == 'Backspace') { else if (e.key == 'Backspace') {
if (caretData.index == 0) { if (caretData.index == 0) {
let activeDataIndex = dataList.findIndex(item => item.id == caretData.activeData.id) let activeDataIndex = dataList.findIndex(item => item.id == caretData.activeData.id)
...@@ -475,7 +473,6 @@ var ADocEditor = function (customConfig) { ...@@ -475,7 +473,6 @@ var ADocEditor = function (customConfig) {
} }
else if (e.key.length == 1 && !e.ctrlKey && !e.metaKey) { // displayable text else if (e.key.length == 1 && !e.ctrlKey && !e.metaKey) { // displayable text
// ***** 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) 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)
...@@ -509,6 +506,14 @@ var ADocEditor = function (customConfig) { ...@@ -509,6 +506,14 @@ var ADocEditor = function (customConfig) {
else if (e.key == 'ArrowDown') { else if (e.key == 'ArrowDown') {
console.log('Down') console.log('Down')
} }
function manageIndentation(value){
caretData.activeData.tabCount += value
if (caretData.activeData.tabCount<0) caretData.activeData.tabCount = 0
else if (caretData.activeData.tabCount>5 ) caretData.activeData.tabCount = 5
return true
}
caretData.blink = false caretData.blink = false
caretData.previousCaret = null caretData.previousCaret = null
reRenderCanvas() reRenderCanvas()
...@@ -565,10 +570,8 @@ var ADocEditor = function (customConfig) { ...@@ -565,10 +570,8 @@ var ADocEditor = function (customConfig) {
reRenderCanvas() reRenderCanvas()
} }
function onBlurHandler(e) { function onBlurHandler(e) {
// console.log('blur')
caretData.blink = true caretData.blink = true
focussedPage = null 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