re-checking paragraphs after updating the assistant

This commit is contained in:
Artur
2026-01-22 13:32:09 +03:00
parent ab65299222
commit 3cd18a29b6
7 changed files with 61 additions and 15 deletions

View File

@ -33,7 +33,11 @@
/// <reference path="./custom-annotator.js" />
/// <reference path="./types.js" />
/** @param {localStorageCustomAssistantItem} assistantData */
/**
* @param {localStorageCustomAssistantItem} assistantData
* @constructor
* @extends CustomAnnotator
*/
function AssistantHint(annotationPopup, assistantData)
{
CustomAnnotator.call(this, annotationPopup, assistantData);

View File

@ -33,7 +33,11 @@
/// <reference path="./custom-annotator.js" />
/// <reference path="./types.js" />
/** @param {localStorageCustomAssistantItem} assistantData */
/**
* @param {localStorageCustomAssistantItem} assistantData
* @constructor
* @extends CustomAnnotator
*/
function AssistantReplaceHint(annotationPopup, assistantData)
{
CustomAnnotator.call(this, annotationPopup, assistantData);

View File

@ -33,7 +33,11 @@
/// <reference path="./custom-annotator.js" />
/// <reference path="./types.js" />
/** @param {localStorageCustomAssistantItem} assistantData */
/**
* @param {localStorageCustomAssistantItem} assistantData
* @constructor
* @extends CustomAnnotator
*/
function AssistantReplace(annotationPopup, assistantData)
{
CustomAnnotator.call(this, annotationPopup, assistantData);

View File

@ -31,7 +31,12 @@
*/
/// <reference path="./types.js" />
/// <reference path="../text-annotations/text-annotator.js" />
/**
* @constructor
* @extends TextAnnotator
*/
function CustomAnnotator(annotationPopup, assistantData)
{
TextAnnotator.call(this, annotationPopup);
@ -72,4 +77,4 @@ CustomAnnotator.prototype._handleNewRangePositions = async function(range, paraI
let annotRange = this.getAnnotationRangeObj(paraId, rangeId);
Asc.Editor.callMethod("RemoveAnnotationRange", [annotRange]);
}
};
};

View File

@ -42,7 +42,7 @@
class CustomAssistantManager {
constructor() {
/**
* @type {Map<string, TextAnnotator>}
* @type {Map<string, Assistant>}
*/
this._customAssistants = new Map();
this._isCustomAssistantInit = new Map();
@ -53,15 +53,13 @@ class CustomAssistantManager {
/**
* @param {localStorageCustomAssistantItem} assistantData
* @returns
*/
createAssistant(assistantData) {
let assistant = this._customAssistants.get(assistantData.id);
if (assistant) {
assistant.assistantData = assistantData;
assistant.type = assistantData.type;
return assistant;
if (this._customAssistants.has(assistantData.id)) {
return this._updateAssistant(assistantData);
}
/** @type {Assistant | null} */
let assistant = null;
switch (assistantData.type) {
case 0:
assistant = new AssistantHint(customAnnotationPopup, assistantData);
@ -72,10 +70,9 @@ class CustomAssistantManager {
case 2:
assistant = new AssistantReplace(customAnnotationPopup, assistantData);
break;
default:
throw new Error(
`Unknown assistant type: ${assistantData.type}`
);
}
if (!assistant) {
throw new Error("Unknown custom assistant type: " + assistantData.type);
}
this._isCustomAssistantInit.set(assistantData.id, false);
@ -84,6 +81,34 @@ class CustomAssistantManager {
return assistant;
}
/**
* @param {localStorageCustomAssistantItem} assistantData
*/
_updateAssistant(assistantData) {
let assistant = this._customAssistants.get(assistantData.id);
if (!assistant) {
throw new Error("Custom assistant not found: " + assistantData.id);
}
assistant.assistantData = assistantData;
assistant.type = assistantData.type;
const isRunning = this._isCustomAssistantRunning.get(assistantData.id);
this._paragraphsStack.forEach((value, paraId) => {
assistant.onChangeParagraph(
paraId,
value.recalcId,
value.text,
value.annotations
);
});
const paragraphIdsToUpdate = [...assistant.checked];
if (isRunning) {
assistant.checkParagraphs(paragraphIdsToUpdate);
}
return assistant;
}
/** @param {string} assistantId */
deleteAssistant(assistantId) {

View File

@ -62,3 +62,6 @@
* @typedef {ReplaceHintInfoForPopup | HintInfoForPopup | ReplaceInfoForPopup} InfoForPopup
*/
/**
* @typedef {CustomAnnotator & TextAnnotator & AssistantHint & AssistantReplaceHint & AssistantReplace} Assistant
*/

View File

@ -40,6 +40,7 @@ function TextAnnotator(annotatorPopup)
/** @type {Object.<string, {recalcId: number, text: string}>} */
this.waitParagraphs = {};
this.paraToCheck = new Set();
/** @type {Set<string>} */
this.checked = new Set(); // was checked on the previous request
this.type = -1;