Support for grammar rule enable/disable

This commit is contained in:
Simon Rozman 2024-08-12 14:05:31 +02:00
parent 04c7f63b5c
commit b3badae762

View File

@ -36,6 +36,8 @@ class BesService {
this.hostElement = hostElement
this.textElement = textElement
this.eventSink = eventSink
this.enabledRules = []
this.disabledRules = []
this.enabledCategories = []
this.disabledCategories = []
this.results = [] // Results of grammar-checking, one per each block/paragraph of text
@ -134,6 +136,29 @@ class BesService {
BesService.getServiceByElement(hostElement)?.unregister()
}
/**
* Enables given grammar rule.
*
* @param {String} rule Rule ID. For the list of rule IDs, see /api/v2/configinfo output.
*/
enableRule(rule) {
this.enabledRules.push(rule)
this.disabledRules = this.disabledRules.filter(value => value !== rule)
this.scheduleProofing(10)
}
/**
* Disables given grammar rule.
*
* @param {String} rule Rule ID. For the list of rule IDs, see /api/v2/configinfo output.
*/
disableRule(rule) {
this.enabledRules = this.enabledRules.filter(value => value !== rule)
this.disabledRules.push(rule)
this.scheduleProofing(10)
return this
}
/**
* Enables all grammar rules of the given category.
*
@ -561,6 +586,8 @@ class BesTreeService extends BesService {
)
}),
language: node.lang ? node.lang : 'sl',
enabledRules: this.enabledRules.join(','),
disabledRules: this.disabledRules.join(','),
enabledCategories: this.enabledCategories.join(','),
disabledCategories: this.disabledCategories.join(','),
enabledOnly: 'false'
@ -1196,6 +1223,8 @@ class BesPlainTextService extends BesService {
]
}),
language: this.hostElement.lang ? this.hostElement.lang : 'sl',
enabledRules: this.enabledRules.join(','),
disabledRules: this.disabledRules.join(','),
enabledCategories: this.enabledCategories.join(','),
disabledCategories: this.disabledCategories.join(','),
enabledOnly: 'false'