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.
This commit is contained in:
Simon Rozman 2025-03-04 09:21:35 +01:00
parent a507f24326
commit 9c2151f182

View File

@ -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
}