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
4196195b
Commit
4196195b
authored
Jan 11, 2024
by
ramdayalmunda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
place caret on clicking
parent
9cf6d76d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
13 deletions
+51
-13
a-doc-editor2.js
dist/assets/a-doc-editor2.js
+51
-13
No files found.
dist/assets/a-doc-editor2.js
View file @
4196195b
...
@@ -14,7 +14,7 @@ var ADocEditor = function (customConfig) {
...
@@ -14,7 +14,7 @@ var ADocEditor = function (customConfig) {
tabWidth
:
20
,
// mm
tabWidth
:
20
,
// mm
},
},
style
:
{
style
:
{
fontSize
:
20
,
// this is in mm
fontSize
:
16
,
// this is in mm
fontFamily
:
'Calibri'
,
fontFamily
:
'Calibri'
,
bold
:
false
,
bold
:
false
,
italic
:
false
,
italic
:
false
,
...
@@ -39,7 +39,7 @@ var ADocEditor = function (customConfig) {
...
@@ -39,7 +39,7 @@ var ADocEditor = function (customConfig) {
index
:
0
,
index
:
0
,
timeout
:
null
,
timeout
:
null
,
timeoutDuration
:
800
,
timeoutDuration
:
800
,
blink
:
fals
e
,
blink
:
tru
e
,
pageIndex
:
0
,
pageIndex
:
0
,
caretSize
:
config
.
style
.
fontSize
,
caretSize
:
config
.
style
.
fontSize
,
previousCaret
:
null
,
previousCaret
:
null
,
...
@@ -142,6 +142,7 @@ var ADocEditor = function (customConfig) {
...
@@ -142,6 +142,7 @@ var ADocEditor = function (customConfig) {
reConfigure
(
customConfig
)
reConfigure
(
customConfig
)
reRenderCanvas
()
reRenderCanvas
()
addGlobalEvents
()
}
}
function
reConfigure
(
newConfig
)
{
function
reConfigure
(
newConfig
)
{
if
(
newConfig
?.
size
&&
paperSizes
[
newConfig
?.
size
])
{
config
.
pageSetup
=
{
...
paperSizes
[
newConfig
.
size
],
size
:
newConfig
.
size
}
}
if
(
newConfig
?.
size
&&
paperSizes
[
newConfig
?.
size
])
{
config
.
pageSetup
=
{
...
paperSizes
[
newConfig
.
size
],
size
:
newConfig
.
size
}
}
...
@@ -400,7 +401,6 @@ var ADocEditor = function (customConfig) {
...
@@ -400,7 +401,6 @@ var ADocEditor = function (customConfig) {
}
}
function keydownHandler(e) {
function keydownHandler(e) {
console.clear()
if (e.altKey) return
if (e.altKey) return
else if (e.key == 'Backspace') {
else if (e.key == 'Backspace') {
if (caretData.index == 0) {
if (caretData.index == 0) {
...
@@ -459,22 +459,52 @@ var ADocEditor = function (customConfig) {
...
@@ -459,22 +459,52 @@ var ADocEditor = function (customConfig) {
}
}
caretData.blink = false
caretData.blink = false
caretData.previousCaret = null
caretData.previousCaret = null
reRenderCanvas(dataList)
reRenderCanvas()
}
function placeCaret( cursor={ x: 0, y: 0 } ){
let found = false
for( let l=0; l<lines.length; l++ ){
if ( (cursor.y <= lines[l].y) && (cursor.y>= (lines[l].maxFontSize*pxMmRatio)) ){
let dataSet = dataList[ lines[l].dataIndex ]
for ( let c=lines[l].charStartIndex; c<=lines[l].charEndIndex; c++ ){
if ( (cursor.x >= dataSet.formatedText[c].x) && (cursor.x<= (dataSet.formatedText[c].width+dataSet.formatedText[c].x))){
caretData.activeData = dataSet
if ( cursor.x <= dataSet.formatedText[c].x+dataSet.formatedText[c].width/2 ){
caretData.index = c
}else{
caretData.index = c+1
}
found = true
caretData.blink = false
renderCaret(true)
return
}
}
if ( found )break; // break only when the caret index is determined
}
}
if (!found){
console.log('no char found')
}
}
}
function mousedownHandler(e) {
function mousedownHandler(e) {
console.clear()
if (focussedPage) {
if (focussedPage) {
console.log('mouse down', e.target)
const rect = e.target.getBoundingClientRect(); // Get the position of the canvas
const rect = e.target.getBoundingClientRect(); // Get the position of the canvas
const x = e.clientX - rect.left; // Adjusted X coordinate
//
const x = e.clientX - rect.left; // Adjusted X coordinate
const y = e.clientY - rect.top; // Adjusted Y coordinate
//
const y = e.clientY - rect.top; // Adjusted Y coordinate
const width = Math.round(rect.width)
//
const width = Math.round(rect.width)
const height = Math.round(rect.height)
//
const height = Math.round(rect.height)
cons
ole.log(`
$
{
x
}
$
{
y
}
--
$
{
width
}
$
{
height
}
`)
;
cons
t pxX = (e.clientX - rect.left)*config.pageSetup.pxWidth/rect.width
;
cons
ole.log(dataList)
cons
t pxY = (e.clientY - rect.top)*config.pageSetup.pxHeight/rect.height;
console.log(lines
)
placeCaret({ x:pxX, y: pxY }
)
}
}
}
}
function onFocusHandler(e) {
function onFocusHandler(e) {
...
@@ -543,6 +573,14 @@ var ADocEditor = function (customConfig) {
...
@@ -543,6 +573,14 @@ var ADocEditor = function (customConfig) {
}
}
function onMouseWheelHandler(e){
if (e.ctrlKey || e.metaKey) e.preventDefault()
}
function addGlobalEvents(e){
shadow.querySelector('.page-list').addEventListener('wheel', onMouseWheelHandler)
}
var returnObj = {
var returnObj = {
addFonts,
addFonts,
getConfiguration() { return JSON.parse(JSON.stringify(config)) },
getConfiguration() { return JSON.parse(JSON.stringify(config)) },
...
...
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