Support for grammar rule category enable/disable
This commit is contained in:
72
service.js
72
service.js
@@ -36,6 +36,8 @@ class BesService {
|
||||
this.hostElement = hostElement
|
||||
this.textElement = textElement
|
||||
this.eventSink = eventSink
|
||||
this.enabledCategories = []
|
||||
this.disabledCategories = []
|
||||
this.results = [] // Results of grammar-checking, one per each block/paragraph of text
|
||||
this.createCorrectionPanel()
|
||||
|
||||
@@ -132,6 +134,42 @@ class BesService {
|
||||
BesService.getServiceByElement(hostElement)?.unregister()
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables all grammar rules of the given category.
|
||||
*
|
||||
* @param {String} cat Category ID. For the list of category IDs, see Readme.md.
|
||||
*/
|
||||
enableCategory(cat) {
|
||||
this.enabledCategories.push(cat)
|
||||
this.disabledCategories = this.disabledCategories.filter(
|
||||
value => value !== cat
|
||||
)
|
||||
if (this.timer) clearTimeout(this.timer)
|
||||
this.timer = setTimeout(() => {
|
||||
this.proofAll()
|
||||
delete this.timer
|
||||
}, 10)
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables all grammar rules of the given category.
|
||||
*
|
||||
* @param {String} cat Category ID. For the list of category IDs, see Readme.md.
|
||||
*/
|
||||
disableCategory(cat) {
|
||||
this.enabledCategories = this.enabledCategories.filter(
|
||||
value => value !== cat
|
||||
)
|
||||
this.disabledCategories.push(cat)
|
||||
if (this.timer) clearTimeout(this.timer)
|
||||
this.timer = setTimeout(() => {
|
||||
this.proofAll()
|
||||
delete this.timer
|
||||
}, 10)
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* Called initially when grammar-checking run is started
|
||||
*/
|
||||
@@ -518,7 +556,10 @@ class BesTreeService extends BesService {
|
||||
x.markup ? { markup: x.text } : { text: x.text }
|
||||
)
|
||||
}),
|
||||
language: node.lang ? node.lang : 'sl'
|
||||
language: node.lang ? node.lang : 'sl',
|
||||
enabledCategories: this.enabledCategories.join(','),
|
||||
disabledCategories: this.disabledCategories.join(','),
|
||||
enabledOnly: 'false'
|
||||
})
|
||||
}),
|
||||
{ signal }
|
||||
@@ -845,7 +886,11 @@ class BesDOMService extends BesTreeService {
|
||||
service = new BesDOMService(hostElement, eventSink)
|
||||
if (service.eventSink && 'register' in service.eventSink)
|
||||
service.eventSink.register(service)
|
||||
service.proofAll()
|
||||
// Defer proofing giving user a chance to configure the service.
|
||||
service.timer = setTimeout(() => {
|
||||
service.proofAll()
|
||||
delete service.timer
|
||||
}, 10)
|
||||
return service
|
||||
}
|
||||
|
||||
@@ -933,7 +978,11 @@ class BesCKService extends BesTreeService {
|
||||
service = new BesCKService(hostElement, ckEditorInstance, eventSink)
|
||||
if (service.eventSink && 'register' in service.eventSink)
|
||||
service.eventSink.register(service)
|
||||
service.proofAll()
|
||||
// Defer proofing giving user a chance to configure the service.
|
||||
service.timer = setTimeout(() => {
|
||||
service.proofAll()
|
||||
delete service.timer
|
||||
}, 10)
|
||||
return service
|
||||
}
|
||||
|
||||
@@ -1154,7 +1203,10 @@ class BesPlainTextService extends BesService {
|
||||
}
|
||||
]
|
||||
}),
|
||||
language: this.hostElement.lang ? this.hostElement.lang : 'sl'
|
||||
language: this.hostElement.lang ? this.hostElement.lang : 'sl',
|
||||
enabledCategories: this.enabledCategories.join(','),
|
||||
disabledCategories: this.disabledCategories.join(','),
|
||||
enabledOnly: 'false'
|
||||
})
|
||||
}),
|
||||
{ signal }
|
||||
@@ -1409,7 +1461,11 @@ class BesDOMPlainTextService extends BesPlainTextService {
|
||||
service = new BesDOMPlainTextService(hostElement, eventSink)
|
||||
if (service.eventSink && 'register' in service.eventSink)
|
||||
service.eventSink.register(service)
|
||||
service.proofAll()
|
||||
// Defer proofing giving user a chance to configure the service.
|
||||
service.timer = setTimeout(() => {
|
||||
service.proofAll()
|
||||
delete service.timer
|
||||
}, 10)
|
||||
return service
|
||||
}
|
||||
|
||||
@@ -1551,7 +1607,11 @@ class BesTAService extends BesPlainTextService {
|
||||
service = new BesTAService(hostElement, eventSink)
|
||||
if (service.eventSink && 'register' in service.eventSink)
|
||||
service.eventSink.register(service)
|
||||
service.proofAll()
|
||||
// Defer proofing giving user a chance to configure the service.
|
||||
service.timer = setTimeout(() => {
|
||||
service.proofAll()
|
||||
delete service.timer
|
||||
}, 10)
|
||||
return service
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user