mirror of
https://github.com/ONLYOFFICE/onlyoffice.github.io.git
synced 2026-04-07 14:04:30 +08:00
Implement accept/close buttons for grammar correction
This commit is contained in:
@ -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>
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user