Refactor ruleType logic to make it accessible within other besService subclasses

This commit is contained in:
Aljaž Grilc 2024-06-05 10:18:55 +02:00
parent 54ba1dea33
commit edbe39722f

View File

@ -49,6 +49,16 @@ class BesService {
this.resizeObserver = new ResizeObserver(this.onResize.bind(this)) this.resizeObserver = new ResizeObserver(this.onResize.bind(this))
this.resizeObserver.observe(this.hostElement) 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) 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 = const ruleType =
ruleTypes[match.rule.id] || 'bes-spelling-mistake' this.ruleTypes[match.rule.id] || 'bes-spelling-mistake'
const { clientRects, highlights } = this.addMistakeMarkup( const { clientRects, highlights } = this.addMistakeMarkup(
range, range,
ruleType ruleType
@ -1206,13 +1206,19 @@ class BesPlainTextService extends BesService {
nodes[nodeIdx].node, nodes[nodeIdx].node,
matchEnd - nodes[nodeIdx].start 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({ matches.push({
rects: clientRects, rects: clientRects,
highlights: highlights, highlights: highlights,
range: matchRange, range: matchRange,
match: match match: match,
ruleType: ruleType
}) })
}) })
this.markProofed(paragraphRange, matches) this.markProofed(paragraphRange, matches)