Compare commits

...

2 Commits

Author SHA1 Message Date
2b54735175 Reformat code 2025-03-04 09:21:51 +01:00
9c2151f182 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.
2025-03-04 09:21:35 +01:00

View File

@ -886,10 +886,11 @@ class BesService {
* @param {Number} scale Sign scale
* @param {Number} dpr Device pixel ratio
*/
setCtxFont(scale, dpr)
{
setCtxFont(scale, dpr) {
const styles = window.getComputedStyle(this.canvasPanel)
this.ctx.font = `${styles.fontStyle} ${styles.fontWeight} ${14 * scale * dpr}px ${styles.fontFamily}`
this.ctx.font = `${styles.fontStyle} ${styles.fontWeight} ${
14 * scale * dpr
}px ${styles.fontFamily}`
}
/**
@ -944,10 +945,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 +1525,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 +2193,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
}
@ -2467,11 +2474,13 @@ class BesTAService extends BesPlainTextService {
parseFloat(styles.paddingRight) -
parseFloat(styles.borderRightWidth)
}px`
textElement.style.height = `${rect.height -
textElement.style.height = `${
rect.height -
parseFloat(styles.borderTopWidth) -
parseFloat(styles.paddingTop) -
parseFloat(styles.paddingBottom) -
parseFloat(styles.borderBottomWidth)}px`
parseFloat(styles.borderBottomWidth)
}px`
}
/**