Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
a-doc-editor
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ramdayal Munda
a-doc-editor
Commits
2d66b649
Commit
2d66b649
authored
Jan 10, 2024
by
ramdayalmunda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simple left and right arrow fixed
parent
bae5be2c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
8 deletions
+39
-8
a-doc-editor2.js
dist/assets/a-doc-editor2.js
+39
-8
No files found.
dist/assets/a-doc-editor2.js
View file @
2d66b649
...
...
@@ -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
)
},
}
var
pageList
=
[]
var
focussedPage
=
null
var
lastFocussedPage
=
null
var
isRendering
=
false
function
initialize
()
{
config
=
JSON
.
parse
(
JSON
.
stringify
(
defaultConfig
))
...
...
@@ -195,7 +197,7 @@ var ADocEditor = function (customConfig) {
calculateTextSizeAndPosition
()
renderLines
()
caretData
.
previousCaret
=
null
renderCaret
()
renderCaret
(
true
)
function
calculateTextSizeAndPosition
()
{
...
...
@@ -306,7 +308,7 @@ var ADocEditor = function (customConfig) {
return
}
function renderCaret() {
function renderCaret(
toLoop
) {
clearTimeout(caretData.timeout)
let ctx = pageList[0].el.getContext('2d', { willReadFrequently: true })
ctx.save()
...
...
@@ -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 data = imageData.data;
caretData.previousCaret = { imageData: structuredClone(imageData), x, y }
...
...
@@ -349,9 +351,11 @@ var ADocEditor = function (customConfig) {
}
ctx.restore()
caretData.timeout = setTimeout(() => {
renderCaret()
}, caretData.timeoutDuration)
if(toLoop){
caretData.timeout = setTimeout(() => {
renderCaret(true)
}, caretData.timeoutDuration)
}
return
}
function getCharacterWidth(char, style) {
...
...
@@ -425,12 +429,34 @@ var ADocEditor = function (customConfig) {
caretData.activeData = 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()
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.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.previousCaret = null
reRenderCanvas(dataList)
...
...
@@ -439,10 +465,15 @@ var ADocEditor = function (customConfig) {
// console.log('mouse down')
}
function onFocusHandler(e) {
focussedPage = e.target
lastFocussedPage = e.target
reRenderCanvas()
}
function onBlurHandler(e) {
// console.log('blur')
caretData.blink = true
focussedPage = null
renderCaret()
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment