From 9c2151f18249fd7ab1cec9da3feb903b72f2f9ee Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Tue, 4 Mar 2025 09:21:35 +0100 Subject: [PATCH] Add clickable tolerance around grammar mistakes Users are complaining it is hard to make a click on a mistake when mistake is covering relative small portion of the text. --- service.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/service.js b/service.js index c4bb8a6..1aebfc4 100644 --- a/service.js +++ b/service.js @@ -944,10 +944,16 @@ class BesService { * @param {Number} x X coordinate * @param {Number} y Y coordinate * @param {DOMRect} rect Rectangle + * @param {Number} tolerance Extra margin around the rectangle treated as "inside" * @returns */ - static isPointInRect(x, y, rect) { - return rect.left <= x && x < rect.right && rect.top <= y && y < rect.bottom + static isPointInRect(x, y, rect, tolerance) { + return ( + rect.left - tolerance <= x && + x < rect.right + tolerance && + rect.top - tolerance <= y && + y < rect.bottom + tolerance + ) } /** @@ -1518,7 +1524,7 @@ class BesTreeService extends BesService { for (let result of this.results) { for (let m of result.matches) { for (let rect of m.highlights) { - if (BesService.isPointInRect(x, y, rect)) { + if (BesService.isPointInRect(x, y, rect, 5)) { pointsInRect.push({ el, match: m }) break } @@ -2186,7 +2192,7 @@ class BesPlainTextService extends BesService { for (let result of this.results) { for (let m of result.matches) { for (let rect of m.highlights) { - if (BesService.isPointInRect(x, y, rect)) { + if (BesService.isPointInRect(x, y, rect, 5)) { pointsInRect.push({ el: result.range, match: m }) break }