This commit is contained in:
Simon Rozman 2024-08-12 13:59:16 +02:00
parent eef106c53f
commit 04c7f63b5c

View File

@ -144,12 +144,7 @@ class BesService {
this.disabledCategories = this.disabledCategories.filter( this.disabledCategories = this.disabledCategories.filter(
value => value !== cat value => value !== cat
) )
if (this.timer) clearTimeout(this.timer) this.scheduleProofing(10)
this.timer = setTimeout(() => {
this.proofAll()
delete this.timer
}, 10)
return this
} }
/** /**
@ -162,11 +157,7 @@ class BesService {
value => value !== cat value => value !== cat
) )
this.disabledCategories.push(cat) this.disabledCategories.push(cat)
if (this.timer) clearTimeout(this.timer) this.scheduleProofing(10)
this.timer = setTimeout(() => {
this.proofAll()
delete this.timer
}, 10)
return this return this
} }
@ -505,6 +496,19 @@ class BesTreeService extends BesService {
super.unregister() super.unregister()
} }
/**
* Schedules proofing after given number of milliseconds.
*
* @param {Number} timeout Number of milliseconds to delay proofing start
*/
scheduleProofing(timeout) {
if (this.timer) clearTimeout(this.timer)
this.timer = setTimeout(() => {
this.proofAll()
delete this.timer
}, timeout)
}
/** /**
* Recursively grammar-(re)checks our host DOM tree. * Recursively grammar-(re)checks our host DOM tree.
*/ */
@ -887,10 +891,7 @@ class BesDOMService extends BesTreeService {
if (service.eventSink && 'register' in service.eventSink) if (service.eventSink && 'register' in service.eventSink)
service.eventSink.register(service) service.eventSink.register(service)
// Defer proofing giving user a chance to configure the service. // Defer proofing giving user a chance to configure the service.
service.timer = setTimeout(() => { service.scheduleProofing(10)
service.proofAll()
delete service.timer
}, 10)
return service return service
} }
@ -933,10 +934,7 @@ class BesDOMService extends BesTreeService {
this.repositionAllMarkup() this.repositionAllMarkup()
// Defer grammar-checking to reduce stress on grammar-checking server. // Defer grammar-checking to reduce stress on grammar-checking server.
this.timer = setTimeout(() => { this.scheduleProofing(1000)
this.proofAll()
delete this.timer
}, 1000)
} }
} }
@ -979,10 +977,7 @@ class BesCKService extends BesTreeService {
if (service.eventSink && 'register' in service.eventSink) if (service.eventSink && 'register' in service.eventSink)
service.eventSink.register(service) service.eventSink.register(service)
// Defer proofing giving user a chance to configure the service. // Defer proofing giving user a chance to configure the service.
service.timer = setTimeout(() => { service.scheduleProofing(10)
service.proofAll()
delete service.timer
}, 10)
return service return service
} }
@ -1021,10 +1016,7 @@ class BesCKService extends BesTreeService {
this.repositionAllMarkup() this.repositionAllMarkup()
// Defer grammar-checking to reduce stress on grammar-checking server. // Defer grammar-checking to reduce stress on grammar-checking server.
this.timer = setTimeout(() => { this.scheduleProofing(1000)
this.proofAll()
delete this.timer
}, 1000)
}, 0) }, 0)
} }
@ -1462,10 +1454,7 @@ class BesDOMPlainTextService extends BesPlainTextService {
if (service.eventSink && 'register' in service.eventSink) if (service.eventSink && 'register' in service.eventSink)
service.eventSink.register(service) service.eventSink.register(service)
// Defer proofing giving user a chance to configure the service. // Defer proofing giving user a chance to configure the service.
service.timer = setTimeout(() => { service.scheduleProofing(10)
service.proofAll()
delete service.timer
}, 10)
return service return service
} }
@ -1511,10 +1500,7 @@ class BesDOMPlainTextService extends BesPlainTextService {
this.repositionAllMarkup() this.repositionAllMarkup()
// Defer grammar-checking to reduce stress on grammar-checking server. // Defer grammar-checking to reduce stress on grammar-checking server.
this.timer = setTimeout(() => { this.scheduleProofing(1000)
this.proofAll()
delete this.timer
}, 1000)
} }
/** /**
@ -1608,10 +1594,7 @@ class BesTAService extends BesPlainTextService {
if (service.eventSink && 'register' in service.eventSink) if (service.eventSink && 'register' in service.eventSink)
service.eventSink.register(service) service.eventSink.register(service)
// Defer proofing giving user a chance to configure the service. // Defer proofing giving user a chance to configure the service.
service.timer = setTimeout(() => { service.scheduleProofing(10)
service.proofAll()
delete service.timer
}, 10)
return service return service
} }
@ -1786,10 +1769,7 @@ class BesTAService extends BesPlainTextService {
this.repositionAllMarkup() this.repositionAllMarkup()
// Defer grammar-checking to reduce stress on grammar-checking server. // Defer grammar-checking to reduce stress on grammar-checking server.
this.timer = setTimeout(() => { this.scheduleProofing(1000)
this.proofAll()
delete this.timer
}, 1000)
} }
/** /**