Revise rule classification
The LanguageTool browser plugin marks spelling mistakes with rule(s) which ID starts with "MORFOLOGIK_RULE". This adopts the same logic.
This commit is contained in:
parent
a23037d23a
commit
56a27c8432
43
service2.js
43
service2.js
@ -48,16 +48,6 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,14 +174,19 @@ class BesService {
|
|||||||
* Creates grammar mistake markup in DOM.
|
* Creates grammar mistake markup in DOM.
|
||||||
*
|
*
|
||||||
* @param {Range} range Grammar mistake range
|
* @param {Range} range Grammar mistake range
|
||||||
|
* @param {String} ruleId Grammar mistake rule ID as reported by BesStr
|
||||||
* @returns {Array} Grammar mistake highlight elements
|
* @returns {Array} Grammar mistake highlight elements
|
||||||
*/
|
*/
|
||||||
addMistakeMarkup(range, ruleType) {
|
addMistakeMarkup(range, ruleId) {
|
||||||
const scrollPanelRect = this.scrollPanel.getBoundingClientRect()
|
const scrollPanelRect = this.scrollPanel.getBoundingClientRect()
|
||||||
let highlights = []
|
let highlights = []
|
||||||
for (let rect of range.getClientRects()) {
|
for (let rect of range.getClientRects()) {
|
||||||
const highlight = document.createElement('div')
|
const highlight = document.createElement('div')
|
||||||
highlight.classList.add(ruleType)
|
highlight.classList.add(
|
||||||
|
ruleId.startsWith('MORFOLOGIK_RULE')
|
||||||
|
? 'bes-spelling-mistake'
|
||||||
|
: 'bes-grammar-mistake'
|
||||||
|
)
|
||||||
highlight.style.left = `${rect.left - scrollPanelRect.left}px`
|
highlight.style.left = `${rect.left - scrollPanelRect.left}px`
|
||||||
highlight.style.top = `${rect.top - scrollPanelRect.top}px`
|
highlight.style.top = `${rect.top - scrollPanelRect.top}px`
|
||||||
highlight.style.width = `${rect.width}px`
|
highlight.style.width = `${rect.width}px`
|
||||||
@ -482,13 +477,10 @@ class BesTreeService extends BesService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const ruleType =
|
|
||||||
this.ruleTypes[match.rule.id] || 'bes-spelling-mistake'
|
|
||||||
matches.push({
|
matches.push({
|
||||||
highlights: this.addMistakeMarkup(range, ruleType),
|
highlights: this.addMistakeMarkup(range, match.rule.id),
|
||||||
range: range,
|
range: range,
|
||||||
match: match,
|
match: match
|
||||||
ruleType: ruleType
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
this.markProofed(node, matches)
|
this.markProofed(node, matches)
|
||||||
@ -554,7 +546,10 @@ class BesTreeService extends BesService {
|
|||||||
this.results.forEach(result => {
|
this.results.forEach(result => {
|
||||||
result.matches.forEach(match => {
|
result.matches.forEach(match => {
|
||||||
if (match.highlights) match.highlights.forEach(h => h.remove())
|
if (match.highlights) match.highlights.forEach(h => h.remove())
|
||||||
match.highlights = this.addMistakeMarkup(match.range, match.ruleType)
|
match.highlights = this.addMistakeMarkup(
|
||||||
|
match.range,
|
||||||
|
match.match.rule.id
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -1190,13 +1185,10 @@ class BesPlainTextService extends BesService {
|
|||||||
nodes[nodeIdx].node,
|
nodes[nodeIdx].node,
|
||||||
matchEnd - nodes[nodeIdx].start
|
matchEnd - nodes[nodeIdx].start
|
||||||
)
|
)
|
||||||
const ruleType =
|
|
||||||
this.ruleTypes[match.rule.id] || 'bes-spelling-mistake'
|
|
||||||
matches.push({
|
matches.push({
|
||||||
highlights: this.addMistakeMarkup(matchRange, ruleType),
|
highlights: this.addMistakeMarkup(matchRange, match.rule.id),
|
||||||
range: matchRange,
|
range: matchRange,
|
||||||
match: match,
|
match: match
|
||||||
ruleType: ruleType
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
this.markProofed(paragraphRange, matches)
|
this.markProofed(paragraphRange, matches)
|
||||||
@ -1276,7 +1268,10 @@ class BesPlainTextService extends BesService {
|
|||||||
this.results.forEach(result => {
|
this.results.forEach(result => {
|
||||||
result.matches.forEach(match => {
|
result.matches.forEach(match => {
|
||||||
if (match.highlights) match.highlights.forEach(h => h.remove())
|
if (match.highlights) match.highlights.forEach(h => h.remove())
|
||||||
match.highlights = this.addMistakeMarkup(match.range, match.ruleType)
|
match.highlights = this.addMistakeMarkup(
|
||||||
|
match.range,
|
||||||
|
match.match.rule.id
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user