diff --git a/samples/div-contenteditable.html b/samples/div-contenteditable.html index 750b464..1a5bc4b 100644 --- a/samples/div-contenteditable.html +++ b/samples/div-contenteditable.html @@ -10,8 +10,8 @@ -
-This is an example of a simple <div contenteditable="true">
edit control. Edit the text, resize the control or browser window, scroll around, click...
Tukaj vpišite besedilo ki ga želite popraviti.
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.
diff --git a/service.js b/service.js index 32ad3ad..aee50e4 100644 --- a/service.js +++ b/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 }