From edbe39722f32f3963534ab220ba3294a9298fa2d Mon Sep 17 00:00:00 2001 From: Aljaz Grilc Date: Wed, 5 Jun 2024 10:18:55 +0200 Subject: [PATCH] Refactor ruleType logic to make it accessible within other besService subclasses --- service2.js | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/service2.js b/service2.js index b07e194..b98c5d2 100644 --- a/service2.js +++ b/service2.js @@ -49,6 +49,16 @@ class BesService { this.resizeObserver = new ResizeObserver(this.onResize.bind(this)) this.resizeObserver.observe(this.hostElement) + // TODO: Include missing rules + // Initial user feedback indicated a requirement for clear differentiation between spelling and grammar errors. + this.ruleTypes = { + BESANA_1: 'bes-spelling-mistake', + BESANA_2: 'bes-spelling-mistake', + BESANA_3: 'bes-spelling-mistake', + BESANA_4: 'bes-grammar-mistake', + BESANA_5: 'bes-spelling-mistake' + } + besServices.push(this) } @@ -464,18 +474,8 @@ class BesTreeService extends BesService { } } - // TODO: Initial user feedback indicated a requirement for clear differentiation between spelling and grammar errors. - // So to do that, we need to add a CSS class to the highlight element based on the rule type. - const ruleTypes = { - BESANA_1: 'bes-spelling-mistake', - BESANA_2: 'bes-spelling-mistake', - BESANA_3: 'bes-spelling-mistake', - BESANA_4: 'bes-grammar-mistake', - BESANA_5: 'bes-spelling-mistake' - } const ruleType = - ruleTypes[match.rule.id] || 'bes-spelling-mistake' - + this.ruleTypes[match.rule.id] || 'bes-spelling-mistake' const { clientRects, highlights } = this.addMistakeMarkup( range, ruleType @@ -1206,13 +1206,19 @@ class BesPlainTextService extends BesService { nodes[nodeIdx].node, matchEnd - nodes[nodeIdx].start ) - const { clientRects, highlights } = - this.addMistakeMarkup(matchRange) + + const ruleType = + this.ruleTypes[match.rule.id] || 'bes-spelling-mistake' + const { clientRects, highlights } = this.addMistakeMarkup( + matchRange, + ruleType + ) matches.push({ rects: clientRects, highlights: highlights, range: matchRange, - match: match + match: match, + ruleType: ruleType }) }) this.markProofed(paragraphRange, matches)