Index: gc_lang/fr/webext/content_scripts/menu.js ================================================================== --- gc_lang/fr/webext/content_scripts/menu.js +++ gc_lang/fr/webext/content_scripts/menu.js @@ -3,10 +3,11 @@ /* jshint esversion:6, -W097 */ /* jslint esversion:6 */ /* global oGrammalecte, showError, window, document */ "use strict"; + class GrammalecteButton { constructor () { // the pearl button @@ -37,10 +38,11 @@ } examineNode (xNode) { if (xNode && xNode instanceof HTMLElement) { if (xNode === this.xTextNode) { + this.move(); return; } if ( ( (xNode.tagName == "TEXTAREA" && this._bTextArea && xNode.getAttribute("spellcheck") !== "false") || (xNode.isContentEditable && this._bEditableNode) || (xNode.tagName == "IFRAME" && this._bIframe) ) @@ -47,10 +49,14 @@ && xNode.style.display !== "none" && xNode.style.visibility !== "hidden" && !(xNode.dataset.grammalecte_button && xNode.dataset.grammalecte_button == "false") ) { this.xTextNode = xNode; this.show() } + else { + this.xTextNode = null; + this.hide(); + } } else { this.xTextNode = null; this.hide(); } @@ -57,21 +63,26 @@ } show () { if (this.xTextNode) { this.xButton.style.display = "none"; // we hide it before showing it again to relaunch the animation - let oCoord = oGrammalecte.getElementCoord(this.xTextNode); - //console.log("top:", oCoord.left, "bottom:", oCoord.top, "left:", oCoord.bottom, "right:", oCoord.right); - this.xButton.style.top = `${oCoord.bottom}px`; - this.xButton.style.left = `${oCoord.left}px`; + this.move(); this.xButton.style.display = "block"; } } hide () { this.xButton.style.display = "none"; } + + move () { + if (this.xTextNode) { + let oCoord = oGrammalecte.getElementCoord(this.xTextNode); + this.xButton.style.top = `${oCoord.bottom}px`; + this.xButton.style.left = `${oCoord.left}px`; + } + } insertIntoPage () { this.bShadow = document.body.createShadowRoot || document.body.attachShadow; if (this.bShadow) { this.xShadowBtn = oGrammalecte.createNode("div", { style: "display:none; position:absolute; width:0; height:0;" }); Index: gc_lang/fr/webext/content_scripts/panel.js ================================================================== --- gc_lang/fr/webext/content_scripts/panel.js +++ gc_lang/fr/webext/content_scripts/panel.js @@ -17,10 +17,11 @@ this.bFlexible = bFlexible; this.bHorizStrech = false; this.bVertStrech = false; this.nPositionX = 2; this.nPositionY = 2; + this.bOpened = false; this.bWorking = false; this.bShadow = document.body.createShadowRoot || document.body.attachShadow; if (this.bShadow) { this.xShadowPanel = oGrammalecte.createNode("div", {id: this.sId+"_shadow", style: "width:0;height:0;"}); @@ -142,14 +143,16 @@ } } show () { this.xPanel.style.display = "flex"; + this.bOpened = true; } hide () { this.xPanel.style.display = "none"; + this.bOpened = false; } center () { this.nPosition = 5; this.setSizeAndPosition(); Index: gc_lang/fr/webext/content_scripts/panel_gc.js ================================================================== --- gc_lang/fr/webext/content_scripts/panel_gc.js +++ gc_lang/fr/webext/content_scripts/panel_gc.js @@ -273,10 +273,13 @@ endTimer () { window.clearTimeout(this.nTimer); } recheckParagraph (iParaNum) { + if (!this.bOpened) { + return; + } let sParagraphId = "grammalecte_paragraph" + iParaNum; let xParagraph = this.xParent.getElementById(sParagraphId); this._blockParagraph(xParagraph); let sText = this.purgeText(xParagraph.textContent); oGrammalecteBackgroundPort.parseAndSpellcheck1(sText, "__GrammalectePanel__", sParagraphId); @@ -284,10 +287,13 @@ this.oTextControl.write(); } refreshParagraph (sParagraphId, oResult) { // function called when results are sent by the Worker + if (!this.bOpened) { + return; + } try { let xParagraph = this.xParent.getElementById(sParagraphId); // save caret position let [nStart, nEnd] = oGrammalecte.getCaretPosition(xParagraph); xParagraph.dataset.caret_position_start = nStart; @@ -1038,28 +1044,32 @@ write () { if (this.xNode !== null) { if (this.bResultInEvent) { const xEvent = new CustomEvent("GrammalecteResult", { detail: JSON.stringify({ sType: "text", sText: this.getText() }) }); this.xNode.dispatchEvent(xEvent); - //console.log("Text to xNode:", xEvent.detail); + console.log("[Grammalecte debug] Text sent to xNode via event:", xEvent.detail); } else if (this.bTextArea) { this.xNode.value = this.getText(); + console.log("[Grammalecte debug] text written in textarea:", this.getText()); } else if (this.bIframe) { //console.log(this.getText()); } else { + let sText = ""; this.eraseNodeContent(); this.dParagraph.forEach((val, key) => { this.xNode.appendChild(document.createTextNode(val.normalize("NFC"))); this.xNode.appendChild(document.createElement("br")); + sText += val.normalize("NFC") + "\n"; }); + console.log("[Grammalecte debug] text written in editable node:", sText); } } else if (this.xResultNode !== null) { const xEvent = new CustomEvent("GrammalecteResult", { detail: JSON.stringify({ sType: "text", sText: this.getText() }) }); this.xResultNode.dispatchEvent(xEvent); - //console.log("Text to xResultNode:", xEvent.detail); + console.log("[Grammalecte debug] Text sent to xResultNode via event:", xEvent.detail); } } }