From 820bf07b9d7fe2a48abefe614c048d65467c4638 Mon Sep 17 00:00:00 2001 From: Ilya Kirillov Date: Thu, 25 Sep 2025 14:37:25 +0300 Subject: [PATCH] [de] Add a paragraph to the annotator when its content changes --- configs/cell.json | 2 +- configs/slide.json | 2 +- configs/visio.json | 4 +-- configs/word.json | 2 +- word/Editor/DocumentContentElementBase.js | 16 +++++++---- word/Editor/Paragraph.js | 4 +++ word/Editor/custom-text-annotator.js | 34 +++++++++++++++++++---- word/Editor/document-visitor.js | 4 +++ 8 files changed, 52 insertions(+), 16 deletions(-) diff --git a/configs/cell.json b/configs/cell.json index cc48c4f9f4..2e7054b169 100644 --- a/configs/cell.json +++ b/configs/cell.json @@ -303,7 +303,6 @@ "word/Editor/Layout/Base.js", "word/Editor/Layout/PrintView.js", "word/Editor/Layout/ReadView.js", - "word/Editor/custom-text-annotator.js", "word/Editor/DocumentContentBase.js", "word/Editor/Document.js", "word/Editor/document-composite-input.js", @@ -415,6 +414,7 @@ "common/Native/native_graphics.js", "word/Editor/document-visitor.js", + "word/Editor/custom-text-annotator.js", "vendor/easysax.js", "common/openxml.js" diff --git a/configs/slide.json b/configs/slide.json index 415aa5733e..5935fcbea5 100644 --- a/configs/slide.json +++ b/configs/slide.json @@ -312,7 +312,6 @@ "word/Editor/document/document-page-column.js", "word/Editor/document/document-page-section.js", "word/Editor/document/element-section.js", - "word/Editor/custom-text-annotator.js", "word/Editor/DocumentContentBase.js", "word/Editor/Document.js", "word/Editor/document-composite-input.js", @@ -398,6 +397,7 @@ "common/Native/native_graphics.js", "word/Editor/document-visitor.js", + "word/Editor/custom-text-annotator.js", "vendor/easysax.js", "common/openxml.js" diff --git a/configs/visio.json b/configs/visio.json index c30a6201c7..df15435749 100644 --- a/configs/visio.json +++ b/configs/visio.json @@ -282,7 +282,6 @@ "word/Editor/document/document-page-column.js", "word/Editor/document/document-page-section.js", "word/Editor/document/element-section.js", - "word/Editor/custom-text-annotator.js", "word/Editor/DocumentContentBase.js", "word/Editor/Document.js", "word/Editor/document-composite-input.js", @@ -372,7 +371,8 @@ "visio/model/SerializeReader.js", "visio/model/SerializeWriter.js", - "word/Editor/document-visitor.js" + "word/Editor/document-visitor.js", + "word/Editor/custom-text-annotator.js" ], "desktop": { "min": [ diff --git a/configs/word.json b/configs/word.json index 27dc4b109c..c36c574d45 100644 --- a/configs/word.json +++ b/configs/word.json @@ -275,7 +275,6 @@ "word/Editor/document/document-page-column.js", "word/Editor/document/document-page-section.js", "word/Editor/document/element-section.js", - "word/Editor/custom-text-annotator.js", "word/Editor/DocumentContentBase.js", "word/Editor/Document.js", "word/Editor/document-composite-input.js", @@ -454,6 +453,7 @@ "common/Native/native_graphics.js", "word/Editor/document-visitor.js", + "word/Editor/custom-text-annotator.js", "vendor/easysax.js", "common/openxml.js" diff --git a/word/Editor/DocumentContentElementBase.js b/word/Editor/DocumentContentElementBase.js index dc62c44c7e..c6e815fbbf 100644 --- a/word/Editor/DocumentContentElementBase.js +++ b/word/Editor/DocumentContentElementBase.js @@ -1438,12 +1438,8 @@ CDocumentContentElementBase.prototype.getDrawingDocument = function() */ CDocumentContentElementBase.prototype.getSpelling = function() { - let oLogicDocument = this.GetLogicDocument(); - if(oLogicDocument) - { - return oLogicDocument.Spelling; - } - return null; + let logicDocument = this.GetLogicDocument(); + return logicDocument ? logicDocument.Spelling : null; }; /** * @returns {boolean} @@ -1455,6 +1451,14 @@ CDocumentContentElementBase.prototype.IsSpellingUse = function() return false; return oSpelling.Use; }; +/** + * @returns {?AscWord.CustomTextAnnotator} + */ +CDocumentContentElementBase.prototype.getCustomTextAnnotator = function() +{ + let logicDocument = this.GetLogicDocument(); + return logicDocument && logicDocument.IsDocumentEditor() ? logicDocument.CustomTextAnnotator : null; +}; /** * Получаем настройки рамки для данного элемента * @returns {?CFramePr} diff --git a/word/Editor/Paragraph.js b/word/Editor/Paragraph.js index d38b5f363b..700aca73fb 100644 --- a/word/Editor/Paragraph.js +++ b/word/Editor/Paragraph.js @@ -14757,6 +14757,10 @@ Paragraph.prototype.RequestSpellCheck = function() { oSpelling.AddParagraphToCheck(this); } + + let textAnnotator = this.getCustomTextAnnotator(); + if (textAnnotator) + textAnnotator.addParagraphToCheck(this); } }; /** diff --git a/word/Editor/custom-text-annotator.js b/word/Editor/custom-text-annotator.js index a044d0ccd7..958ea7bd30 100644 --- a/word/Editor/custom-text-annotator.js +++ b/word/Editor/custom-text-annotator.js @@ -53,17 +53,18 @@ this.waitingParagraphs = {}; this.paragraphs = {}; this.checkingParagraphs = {}; + + this.textGetter = new ParagraphText(); } CustomTextAnnotator.prototype.isActive = function() { return true; }; - CustomTextAnnotator.prototype.checkParagraph = function(para) + CustomTextAnnotator.prototype.addParagraphToCheck = function(para) { this.checkingParagraphs[para.GetId()] = para; }; - CustomTextAnnotator.prototype.continueProcessing = function() { if (!this.isActive()) @@ -75,7 +76,7 @@ if (performance.now() - startTime > MAX_ACTION_TIME) break; - let paragraph = this._popNextParagraph(); + let paragraph = this.popNextParagraph(); if (!paragraph) break; @@ -90,7 +91,7 @@ for (let paraId in this.checkingParagraphs) { let paragraph = this.checkingParagraphs[paraId]; - delete this.paragraph[paraId]; + delete this.checkingParagraphs[paraId]; if (!paragraph.IsUseInDocument()) continue; @@ -102,7 +103,30 @@ }; CustomTextAnnotator.prototype.handleParagraph = function(paragraph) { - return null; + this.textGetter.check(paragraph); + console.log(`ParaId=${paragraph.GetId()}; ParaText=${this.textGetter.text}`); + }; + + /** + * + * @constructor + */ + function ParagraphText() + { + AscWord.DocumentVisitor.call(this); + this.text = ""; + } + ParagraphText.prototype = Object.create(AscWord.DocumentVisitor.prototype); + ParagraphText.prototype.constructor = ParagraphText; + ParagraphText.prototype.check = function(paragraph) + { + this.text = ""; + this.traverseParagraph(paragraph); + }; + ParagraphText.prototype.run = function(run) + { + this.text += run.GetText(); + return true; }; //-------------------------------------------------------------export----------------------------------------------- AscWord.CustomTextAnnotator = CustomTextAnnotator; diff --git a/word/Editor/document-visitor.js b/word/Editor/document-visitor.js index 11dc15d5b2..da01237a6d 100644 --- a/word/Editor/document-visitor.js +++ b/word/Editor/document-visitor.js @@ -71,6 +71,10 @@ { this.visitDocContent(docContent.Content); }; + DocumentVisitor.prototype.traverseParagraph = function(paragraph) + { + paragraph.visit(this); + }; DocumentVisitor.prototype.stop = function() { this.stopped = true;