Update onClick logic
This commit is contained in:
parent
0eb3e81974
commit
661449c2b7
@ -10,8 +10,8 @@
|
||||
<script src="../service.js"></script>
|
||||
<script src="common.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<p class="my-block">This is an example of a simple <code><div contenteditable="true"></code> edit control. Edit the text, resize the control or browser window, scroll around, click...</p>
|
||||
<body style="background-color: gray;">
|
||||
<!-- <p class="my-block">This is an example of a simple <code><div contenteditable="true"></code> edit control. Edit the text, resize the control or browser window, scroll around, click...</p> -->
|
||||
<div id="my-editor" class="my-block my-control" contenteditable="true">
|
||||
<p>Tukaj vpišite besedilo ki ga želite popraviti.</p>
|
||||
<p>Prišla je njena lepa hčera. Smatram da tega nebi bilo potrebno storiti. Predavanje je trajalo dve ure. S njim grem v Kamnik. Janez jutri nebo prišel. Prišel je z 100 idejami.</p>
|
||||
|
36
service.js
36
service.js
@ -333,6 +333,7 @@ class BesService {
|
||||
const canvasPanelRect = this.canvasPanel.getBoundingClientRect()
|
||||
const highlights = []
|
||||
this.canvasPanel.classList.add('bes-canvas')
|
||||
|
||||
this.ctx.lineWidth = 1
|
||||
this.ctx.strokeStyle = ruleId.startsWith('MORFOLOGIK_RULE')
|
||||
? '#e91313'
|
||||
@ -393,14 +394,26 @@ class BesService {
|
||||
* @param {DOMRect} rect Rectangle
|
||||
* @returns
|
||||
*/
|
||||
static isPointInRect(x, y, rect) {
|
||||
const globalWidth = rect.globalX + rect.width
|
||||
const globalHeight = rect.globalY + rect.height
|
||||
static isPointInRect(x, y, rect, canvasPanel) {
|
||||
const canvasRect = canvasPanel.getBoundingClientRect()
|
||||
const globalWidth = rect.x + rect.width
|
||||
const globalHeight = rect.y - rect.height
|
||||
|
||||
const newX = x - canvasRect.left
|
||||
const newY = y - canvasRect.top
|
||||
console.log(
|
||||
'x:',
|
||||
newX,
|
||||
'y:',
|
||||
newY,
|
||||
'globalWidth:',
|
||||
globalWidth,
|
||||
'globalHeight:',
|
||||
globalHeight
|
||||
)
|
||||
console.log(rect)
|
||||
return (
|
||||
rect.globalX <= x &&
|
||||
x < globalWidth &&
|
||||
rect.globalY <= y &&
|
||||
y < globalHeight
|
||||
rect.x <= newX && newX < globalWidth && globalHeight <= newY && newY < y
|
||||
)
|
||||
// return rect.left <= x && x < rect.right && rect.top <= y && y < rect.bottom
|
||||
}
|
||||
@ -954,7 +967,14 @@ class BesTreeService extends BesService {
|
||||
for (let result of this.results) {
|
||||
for (let m of result.matches) {
|
||||
for (let h of m.highlights) {
|
||||
if (BesService.isPointInRect(source.clientX, source.clientY, h)) {
|
||||
if (
|
||||
BesService.isPointInRect(
|
||||
source.clientX,
|
||||
source.clientY,
|
||||
h,
|
||||
this.canvasPanel
|
||||
)
|
||||
) {
|
||||
this.popupCorrectionPanel(el, m, source)
|
||||
return
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user