Commit 55662d19 by ramdayalmunda

style fixes

parent 644d57ce
...@@ -12,7 +12,7 @@ var ADocEditor = function (customConfig) { ...@@ -12,7 +12,7 @@ var ADocEditor = function (customConfig) {
element: "", element: "",
pageSetup: { pageSetup: {
width: 210, width: 210,
height: 210, height: 110,
}, },
format: { format: {
background: "#fff", background: "#fff",
...@@ -25,9 +25,12 @@ var ADocEditor = function (customConfig) { ...@@ -25,9 +25,12 @@ var ADocEditor = function (customConfig) {
fontFamily: 'Arial', fontFamily: 'Arial',
bold: false, bold: false,
italic: false, italic: false,
fontColor: "#1e1f77" fontColor: "#1e1f77",
x: 0,
y: 0
}, },
} }
defaultConfig.style.y = defaultConfig.style.fontSize
var config = JSON.parse( JSON.stringify( defaultConfig ) ); var config = JSON.parse( JSON.stringify( defaultConfig ) );
var canvasList = [] var canvasList = []
const dataTypes = [ const dataTypes = [
...@@ -201,12 +204,12 @@ var ADocEditor = function (customConfig) { ...@@ -201,12 +204,12 @@ var ADocEditor = function (customConfig) {
let charWidth = ctx.measureText(dataSet.plainContent[i]).width let charWidth = ctx.measureText(dataSet.plainContent[i]).width
ctx.restore() ctx.restore()
dataSet.formatedText[i] = { dataSet.formatedText[i] = {
...style,
char: dataSet.plainContent[i], char: dataSet.plainContent[i],
width: charWidth, width: charWidth,
x: x, x: x,
y: y, y: y,
canvas: canvas, canvas: canvas,
...style,
} }
x += charWidth x += charWidth
...@@ -283,10 +286,11 @@ var ADocEditor = function (customConfig) { ...@@ -283,10 +286,11 @@ var ADocEditor = function (customConfig) {
focusedCanvas = e.target focusedCanvas = e.target
caretData.blink = false caretData.blink = false
reRenderPages(dataSet) reRenderPages(dataSet)
caretData.interval = setInterval(() => { // // // uncomment this. This is necessary for blinking caret
caretData.blink = !caretData.blink // caretData.interval = setInterval(() => {
reRenderPages(dataSet, true) // caretData.blink = !caretData.blink
}, caretData.intervalDuration) // reRenderPages(dataSet, true)
// }, caretData.intervalDuration)
} }
function onBlurHandler(e) { function onBlurHandler(e) {
focusedCanvas = null focusedCanvas = null
...@@ -302,6 +306,9 @@ var ADocEditor = function (customConfig) { ...@@ -302,6 +306,9 @@ var ADocEditor = function (customConfig) {
caretData.blink = false caretData.blink = false
if (e.shiftKey && e.ctrlKey) { } // ctr+shift combination if (e.shiftKey && e.ctrlKey) { } // ctr+shift combination
if (e.keyCode == 16 || e.keyCode==18 || e.keyCode==20) {
return
}
else if (e.ctrlKey) { else if (e.ctrlKey) {
if (e.keyCode == 8) { // ctrl+backspace: delete the entrite word if (e.keyCode == 8) { // ctrl+backspace: delete the entrite word
let separatedSentence = caretData.activeData.plainContent.slice(0, caretData.index) let separatedSentence = caretData.activeData.plainContent.slice(0, caretData.index)
...@@ -317,11 +324,14 @@ var ADocEditor = function (customConfig) { ...@@ -317,11 +324,14 @@ var ADocEditor = function (customConfig) {
else if (e.keyCode == 13) { // Enter Key else if (e.keyCode == 13) { // Enter Key
if (caretData){ if (caretData){
if (caretData.activeData.type == 0){ // for plain text // just go to next line if (caretData.activeData.type == 0){ // for plain text // just go to next line
let style = caretData?.activeData?.formatedText?.[caretData.activeData.formatedText.length-1]
if (!style) style = caretData?.activeData?.style
if (!style) style = config.style
let newLineData = { let newLineData = {
id: ++counter, id: ++counter,
type: 0, type: 0,
plainContent: "", plainContent: "",
style: JSON.parse( JSON.stringify(caretData.activeData.formatedText[caretData.activeData.formatedText.length-1]) ) style: JSON.parse( JSON.stringify(style) )
} }
newLineData.style.y += newLineData.style.fontSize newLineData.style.y += newLineData.style.fontSize
newLineData.style.x = 0 newLineData.style.x = 0
...@@ -378,16 +388,16 @@ var ADocEditor = function (customConfig) { ...@@ -378,16 +388,16 @@ var ADocEditor = function (customConfig) {
reRenderPages(dataSet) reRenderPages(dataSet)
clearInterval(caretData.interval) clearInterval(caretData.interval)
caretData.interval = setInterval(() => { // // // uncomment this. This is necessary for blinking caret
caretData.blink = !caretData.blink // caretData.interval = setInterval(() => {
reRenderPages(dataSet, true) // caretData.blink = !caretData.blink
}, caretData.intervalDuration) // reRenderPages(dataSet, true)
// }, caretData.intervalDuration)
} }
function setCaretPosition(e){ function setCaretPosition(e){
let rect = e.target.getBoundingClientRect() let rect = e.target.getBoundingClientRect()
// console.log('rect', rect)
let position = { let position = {
xP: e.offsetX/rect.width, xP: e.offsetX/rect.width,
yP: e.offsetY/rect.height, yP: e.offsetY/rect.height,
...@@ -396,11 +406,9 @@ var ADocEditor = function (customConfig) { ...@@ -396,11 +406,9 @@ var ADocEditor = function (customConfig) {
position.x = position.xP*config.pageSetup.canvasWidth position.x = position.xP*config.pageSetup.canvasWidth
position.y = position.yP*config.pageSetup.canvasHeight position.y = position.yP*config.pageSetup.canvasHeight
let lineY = dataSet[canvasData.dataIndex].style.y let lineY = dataSet[canvasData.dataIndex].style.y
console.log('positionY', position.y, dataSet[canvasData.dataIndex].style.fontSize)
for (let i=canvasData.dataIndex; i<dataSet.length; i++){ for (let i=canvasData.dataIndex; i<dataSet.length; i++){
for ( let j=0; j< dataSet[i].formatedText.length; j++ ){ for ( let j=0; j< dataSet[i].formatedText.length; j++ ){
if ( Math.floor( dataSet[i].formatedText[j].x ) == Math.floor(position.x) ){ if ( Math.floor( dataSet[i].formatedText[j].x ) == Math.floor(position.x) ){
console.log('breaked')
break; break;
} }
} }
......
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