Implement accept/close buttons for grammar correction

This commit is contained in:
Ilya Kirillov
2025-10-22 12:46:36 +03:00
parent 7564b82291
commit aa31508c83
3 changed files with 33 additions and 20 deletions

View File

@ -215,13 +215,7 @@
document.getElementById('acceptBtn').addEventListener('click', function ()
{
if (window.parent !== window)
{
window.parent.postMessage({
action: 'accept',
suggestion: errorData.suggestion
}, '*');
}
window.Asc.plugin.sendToPlugin("onAccept");
});
window.Asc.plugin.init = function() {
@ -239,12 +233,7 @@
document.getElementById('closeBtn').addEventListener('click', function ()
{
if (window.parent !== window)
{
window.parent.postMessage({
action: 'close'
}, '*');
}
window.Asc.plugin.sendToPlugin("onClose");
});
</script>
</body>

View File

@ -671,9 +671,14 @@ class Provider extends AI.Provider {\n\
return;
if ("spelling" === obj["name"])
{
spellchecker.setCurrentRange(null, null);
else ("grammar" === obj["name"])
}
else if ("grammar" === obj["name"])
{
grammar.resetCurrentRange();
grammar.closePopup();
}
});
this.attachEditorEvent("onClickAnnotation", function(obj) {

View File

@ -252,8 +252,6 @@ Text to check:`;
}
};
this.onBlur
this.onClickAnnotation = function(paragraphId, ranges)
{
console.log(`Click grammar: para=${paragraphId} ranges=${ranges}`);
@ -290,7 +288,25 @@ Text to check:`;
popup.attachEvent("onWindowReady", function() {
popup.command("onUpdateSuggestion", _t.getSuggestion(paraId, rangeId));
});
popup.attachEvent("onAccept", function() {
popup.attachEvent("onAccept", async function() {
let text = _t.getSuggestion(paraId, rangeId)["suggestion"];
await Asc.Editor.callMethod("StartAction", ["GroupActions"]);
let range = {
paragraphId: paraId,
rangeId: rangeId,
name: "grammar"
};
await Asc.Editor.callMethod("SelectAnnotationRange", [range]);
Asc.scope.text = text;
await Asc.Editor.callCommand(function(){
Api.ReplaceTextSmart([Asc.scope.text]);
});
await Asc.Editor.callMethod("EndAction", ["GroupActions"]);
});
popup.attachEvent("onClose", function() {
_t.closePopup();
@ -298,15 +314,18 @@ Text to check:`;
popup.show(variation);
this.popup = popup;
};
this.resetCurrentRange = function()
{
this.paraId = null;
this.rangeId = null;
};
this.closePopup = function()
{
if (!this.popup)
return;
this.paraId = null;
this.rangeId = null;
this.popup.close();
this.popup = null;
};