Made it so that the assistant does not re-check a paragraph if it was changed automatically by the assistant itself.

This commit is contained in:
Artur
2026-01-22 15:45:09 +03:00
parent 3cd18a29b6
commit 98e742e6fe
5 changed files with 24 additions and 3 deletions

View File

@ -207,6 +207,7 @@ AssistantHint.prototype.getInfoForPopup = function(paraId, rangeId)
*/
AssistantHint.prototype.onAccept = async function(paraId, rangeId)
{
await CustomAnnotator.prototype.onAccept.call(this);
await Asc.Editor.callMethod("StartAction", ["GroupActions"]);
let range = this.getAnnotationRangeObj(paraId, rangeId);

View File

@ -217,6 +217,7 @@ AssistantReplaceHint.prototype.getInfoForPopup = function(paraId, rangeId)
*/
AssistantReplaceHint.prototype.onAccept = async function(paraId, rangeId)
{
await CustomAnnotator.prototype.onAccept.call(this, paraId, rangeId);
let text = this.getAnnotation(paraId, rangeId)["suggestion"];
await Asc.Editor.callMethod("StartAction", ["GroupActions"]);

View File

@ -204,6 +204,7 @@ AssistantReplace.prototype.getInfoForPopup = function(paraId, rangeId)
*/
AssistantReplace.prototype.onAccept = async function(paraId, rangeId)
{
await CustomAnnotator.prototype.onAccept.call(this);
let text = this.getAnnotation(paraId, rangeId)["suggestion"];
await Asc.Editor.callMethod("StartAction", ["GroupActions"]);

View File

@ -42,6 +42,7 @@ function CustomAnnotator(annotationPopup, assistantData)
TextAnnotator.call(this, annotationPopup);
this.assistantData = assistantData;
this.type = assistantData.type;
this._skipNextChangeParagraph = false;
}
CustomAnnotator.prototype = Object.create(TextAnnotator.prototype);
CustomAnnotator.prototype.constructor = CustomAnnotator;
@ -78,3 +79,19 @@ CustomAnnotator.prototype._handleNewRangePositions = async function(range, paraI
Asc.Editor.callMethod("RemoveAnnotationRange", [annotRange]);
}
};
/**
* @param {string[]} paraIds
*/
CustomAnnotator.prototype.checkParagraphs = async function(paraIds)
{
if (this._skipNextChangeParagraph)
{
this._skipNextChangeParagraph = false;
return;
}
TextAnnotator.prototype.checkParagraphs.call(this, paraIds);
};
CustomAnnotator.prototype.onAccept = async function(paraId, rangeId)
{
this._skipNextChangeParagraph = true;
};

View File

@ -93,6 +93,9 @@ class CustomAssistantManager {
assistant.type = assistantData.type;
const isRunning = this._isCustomAssistantRunning.get(assistantData.id);
if (!isRunning) {
return assistant;
}
this._paragraphsStack.forEach((value, paraId) => {
assistant.onChangeParagraph(
@ -103,9 +106,7 @@ class CustomAssistantManager {
);
});
const paragraphIdsToUpdate = [...assistant.checked];
if (isRunning) {
assistant.checkParagraphs(paragraphIdsToUpdate);
}
assistant.checkParagraphs(paragraphIdsToUpdate);
return assistant;
}