service2.js: Fix empty paragraph handling

This commit is contained in:
Simon Rozman 2024-05-22 11:03:54 +02:00
parent 6eac44165f
commit e0e9f1a651

View File

@ -432,9 +432,9 @@ class BesDOMService extends BesTreeService {
case Node.ELEMENT_NODE: case Node.ELEMENT_NODE:
if (this.isBlockElement(node)) { if (this.isBlockElement(node)) {
// Block elements are grammar-checked independently. // Block elements are grammar-checked independently.
this.onProofing()
let result = this.getProofing(node) let result = this.getProofing(node)
if (result) { if (result) {
this.onProofing()
this.onProofingProgress(result.matches.length) this.onProofingProgress(result.matches.length)
return [{ text: `<${node.tagName}/>`, node: node, markup: true }] return [{ text: `<${node.tagName}/>`, node: node, markup: true }]
} }
@ -444,6 +444,7 @@ class BesDOMService extends BesTreeService {
data = data.concat(this.proofNode(el2, abortController)) data = data.concat(this.proofNode(el2, abortController))
if (data.some(x => !x.markup && !/^\s*$/.test(x.text))) { if (data.some(x => !x.markup && !/^\s*$/.test(x.text))) {
// Block element contains some text. // Block element contains some text.
this.onProofing()
const signal = abortController.signal const signal = abortController.signal
fetch( fetch(
new Request(besUrl + '/check', { new Request(besUrl + '/check', {
@ -948,12 +949,16 @@ class BesPlainTextService extends BesService {
paragraphRange.setEnd(nodes[nodeIdx].node, end - nodes[nodeIdx].start) paragraphRange.setEnd(nodes[nodeIdx].node, end - nodes[nodeIdx].start)
while (nodeIdx < nodes.length && nodes[nodeIdx].end <= end) nodeIdx++ while (nodeIdx < nodes.length && nodes[nodeIdx].end <= end) nodeIdx++
this.onProofing()
let result = this.getProofing(paragraphRange) let result = this.getProofing(paragraphRange)
if (result) { if (result) {
this.onProofing()
this.onProofingProgress(result.matches.length) this.onProofingProgress(result.matches.length)
continue continue
} }
let paragraphText = text.substring(start, end)
if (!/^\s*$/.test(paragraphText)) {
// Paragraph contains some text.
this.onProofing()
const signal = this.abortController.signal const signal = this.abortController.signal
fetch( fetch(
new Request(besUrl + '/check', { new Request(besUrl + '/check', {
@ -966,7 +971,7 @@ class BesPlainTextService extends BesService {
data: JSON.stringify({ data: JSON.stringify({
annotation: [ annotation: [
{ {
text: text.substring(start, end) text: paragraphText
} }
] ]
}), }),
@ -1016,6 +1021,7 @@ class BesPlainTextService extends BesService {
}) })
.catch(error => this.onFailedProofingResult(error)) .catch(error => this.onFailedProofingResult(error))
} }
}
this.onProofingProgress(0) this.onProofingProgress(0)
} }