Check grammar and spelling only when pressing button

Also change icons for grammar and spelling
This commit is contained in:
Ilya Kirillov
2025-11-12 15:22:16 +03:00
parent 0d53a1e03b
commit da997d1974
18 changed files with 54 additions and 13 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 429 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 539 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 613 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 789 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 815 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 414 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 477 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 534 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 603 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 624 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 415 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 456 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 516 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 562 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 607 B

View File

@ -828,10 +828,32 @@ function onTranslateSettingsModal() {
translateSettingsWindow.show(variation);
}
function onCheckGrammarSpelling(isCurrent)
async function onCheckGrammarSpelling(isCurrent)
{
// TODO: implement
console.log(`Check grammar & spelling all= ${!isCurrent}`);
console.log(`Check grammar & spelling all= ${!isCurrent}`);
if (isCurrent)
{
let paraIds = await Asc.Editor.callCommand(function(){
let result = [];
let paragraphs = Api.GetDocument().GetRangeBySelect().GetAllParagraphs();
paragraphs.forEach(p => result.push(p.GetInternalId()));
return result;
});
if (spellchecker)
spellchecker.checkParagraphs(paraIds);
if (grammar)
grammar.checkParagraphs(paraIds);
}
else
{
if (spellchecker)
spellchecker.checkAll();
if (grammar)
grammar.checkAll();
}
}
/**

View File

@ -142,13 +142,12 @@ function registerButtons(window, undefined)
{
let buttonSub = new Asc.ButtonContextMenu(buttonMain);
buttonSub.text = "Grammar & Spelling";
buttonSub.icons = getContextMenuButtonIcons("summarization");
buttonSub.icons = getContextMenuButtonIcons("grammar");
buttonSub.editors = ["word"];
buttonSub.addCheckers("Target", "Selection");
let buttonAll = new Asc.ButtonContextMenu(buttonSub);
buttonAll.text = "Check all";
buttonAll.icons = getContextMenuButtonIcons("text-analysis-ai");
buttonAll.editors = ["word"];
buttonAll.addCheckers("Target", "Selection");
@ -158,7 +157,6 @@ function registerButtons(window, undefined)
let buttonCurrent = new Asc.ButtonContextMenu(buttonSub);
buttonCurrent.text = "Check current selection";
buttonCurrent.icons = getContextMenuButtonIcons("text-analysis-ai");
buttonCurrent.editors = ["word"];
buttonCurrent.addCheckers("Target", "Selection");

View File

@ -36,42 +36,63 @@ function TextAnnotator()
this.rangeId = null;
this.paragraphs = {};
this.waitParagraphs = {};
this.paraToCheck = new Set();
this.isCheckAll = true;
this.checked = {};
this.type = -1;
}
TextAnnotator.prototype.onChangeParagraph = async function(paraId, recalcId, text, ranges)
{
// TODO: Update ranges
this.waitParagraphs[paraId] = {
recalcId : recalcId,
text : text
};
this._checkParagraph();
//this.annotateParagraph(paraId, recalcId, text, ranges);
this._checkParagraph(paraId);
};
TextAnnotator.prototype.checkParagraphs = async function(paraIds)
{
this.isCheckAll = false;
this.paraToCheck.clear()
paraIds.array.forEach(paraId => this.paraToCheck.add(paraId));
//for (let paraId in )
paraIds.forEach(paraId => this.paraToCheck.add(paraId));
this.paraToCheck.forEach(paraId => this._checkParagraph(paraId));
};
TextAnnotator.prototype.checkAll = async function()
{
if (this.isCheckAll)
return;
this.isCheckAll = true;
this.checked = {};
};
TextAnnotator.prototype._checkParagraph = function(paraId)
{
if (!this.paraToCheck[paraId] || !this.waitParagraphs[paraId])
if (!this.paraToCheck.has(paraId) || !this.waitParagraphs[paraId])
return;
let recalcId = this.waitParagraphs[paraId].recalcId;
let text = this.waitParagraphs[paraId].text;
// TODO: Temporarily for simplicity
let range = this.getAnnotationRangeObj(paraId);
range["rangeId"] = undefined;
range["all"] = true;
Asc.Editor.callMethod("RemoveAnnotationRange", [range]);
this.annotateParagraph(paraId, recalcId, text);
delete this.waitParagraphs[paraId];
this.paraToCheck.remove;
this.paraToCheck.delete(paraId);
};
TextAnnotator.prototype.annotateParagraph = async function(paraId, recalcId, text)
{
};
TextAnnotator.prototype.openPopup = async function(paraId, rangeId)
{