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 @@ -48,11 +48,11 @@ */ constructor (...args) { super(...args); this.aIgnoredErrors = new Set(); - this.createMenu() + this.createMenu(); this.xPanelContent.style.marginBottom = "6px"; // Editor this.xGCPanelContent = oGrammalecte.createNode("div", {id: "grammalecte_gc_panel_content"}); this.xParagraphList = oGrammalecte.createNode("div", {id: "grammalecte_paragraph_list"}); this.xGCPanelContent.appendChild(this.xParagraphList); @@ -59,11 +59,12 @@ this.xPanelContent.addEventListener("click", onGrammalecteGCPanelClick, false); this.oTooltip = new GrammalecteTooltip(this.xParent, this.xGCPanelContent); this.xPanelContent.appendChild(this.xGCPanelContent); this.xNode = null; this.oTextControl = new GrammalecteTextControl(); - this.nLastResult = 0 + this.nLastResult = 0; + this.iLastEditedParagraph = -1; // Lexicographer this.nLxgCount = 0; this.xLxgPanelContent = oGrammalecte.createNode("div", {id: "grammalecte_lxg_panel_content"}); this.xPanelContent.appendChild(this.xLxgPanelContent); // Conjugueur @@ -81,12 +82,12 @@ this.xEditorButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_button", textContent: "Éditeur"}); this.xLxgButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_button", textContent: "Lexicographe"}); this.xConjButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_button", textContent: "Conjugueur"}); // buttons this.xLexEditButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_subbutton", textContent: "ÉditLex", title: "Ouvrir l’éditeur lexical", style: "background-color: hsl(210, 50%, 40%)"}); - this.xLxgButton.appendChild(this.xLexEditButton) - this.xAutoRefresh = oGrammalecte.createNode("div", {className: "grammalecte_menu_subbutton", textContent: "AutoRafr", title: "Auto-rafraîchissement de la correction grammaticale (3 s après la dernière frappe)"}) + this.xLxgButton.appendChild(this.xLexEditButton); + this.xAutoRefresh = oGrammalecte.createNode("div", {className: "grammalecte_menu_subbutton", textContent: "AutoRafr", title: "Auto-rafraîchissement de la correction grammaticale (3 s après la dernière frappe)"}); this.xEditorButton.appendChild(this.xAutoRefresh); this.bAutoRefresh = oGrammalecte.bAutoRefresh; this.setAutoRefreshButton(); this.xTFButton.onclick = () => { if (!this.bWorking) { @@ -122,14 +123,14 @@ }; this.xLexEditButton.onclick = () => { oGrammalecteBackgroundPort.openLexiconEditor(); }; // Add tabs to menu - this.xMenu.appendChild(this.xTFButton) - this.xMenu.appendChild(this.xEditorButton) - this.xMenu.appendChild(this.xLxgButton) - this.xMenu.appendChild(this.xConjButton) + this.xMenu.appendChild(this.xTFButton); + this.xMenu.appendChild(this.xEditorButton); + this.xMenu.appendChild(this.xLxgButton); + this.xMenu.appendChild(this.xConjButton); this.xPanelBar.appendChild(this.xMenu); } start (what, xResultNode=null) { this.oTooltip.hide(); @@ -238,10 +239,11 @@ xParagraph.addEventListener("input", function (xEvent) { if (this.bAutoRefresh) { // timer for refreshing analysis window.clearTimeout(parseInt(xParagraph.dataset.timer_id, 10)); xParagraph.dataset.timer_id = window.setTimeout(this.recheckParagraph.bind(this), 3000, oResult.iParaNum); + this.iLastEditedParagraph = oResult.iParaNum; } // write text this.oTextControl.setParagraph(parseInt(xEvent.target.dataset.para_num, 10), this.purgeText(xEvent.target.textContent)); this.oTextControl.write(); }.bind(this) @@ -298,12 +300,13 @@ xParagraph.dataset.caret_position_start = nStart; xParagraph.dataset.caret_position_end = nEnd; // erase texte xParagraph.textContent = ""; // recreate and retag - this._tagParagraph(xParagraph, oResult.sParagraph, sParagraphId.slice(21), oResult.aGrammErr, oResult.aSpellErr); - this._freeParagraph(xParagraph); + let sParaNum = sParagraphId.slice(21); + this._tagParagraph(xParagraph, oResult.sParagraph, sParaNum, oResult.aGrammErr, oResult.aSpellErr); + this._freeParagraph(xParagraph, parseInt(sParaNum, 10)); } catch (e) { showError(e); } } @@ -387,13 +390,13 @@ this.xParent.getElementById("grammalecte_check"+xParagraph.dataset.para_num).style.backgroundColor = "hsl(0, 50%, 50%)"; this.xParent.getElementById("grammalecte_check"+xParagraph.dataset.para_num).style.boxShadow = "0 0 0 3px hsla(0, 0%, 50%, .2)"; this.xParent.getElementById("grammalecte_check"+xParagraph.dataset.para_num).style.animation = "grammalecte-pulse 1s linear infinite"; } - _freeParagraph (xParagraph) { + _freeParagraph (xParagraph, iParaNum) { xParagraph.contentEditable = "true"; - if (xParagraph.dataset.caret_position_start !== "-1") { + if (iParaNum == this.iLastEditedParagraph && xParagraph.dataset.caret_position_start !== "-1") { let nStart = parseInt(xParagraph.dataset.caret_position_start, 10); let nEnd = parseInt(xParagraph.dataset.caret_position_end, 10); oGrammalecte.setCaretPosition(xParagraph, nStart, nEnd); } this.xParent.getElementById("grammalecte_check"+xParagraph.dataset.para_num).textContent = "↻"; @@ -413,10 +416,11 @@ let iParaNum = parseInt(sErrorId.slice(0, sErrorId.indexOf("-")), 10); this.oTextControl.setParagraph(iParaNum, this.purgeText(this.xParent.getElementById("grammalecte_paragraph" + iParaNum).textContent)); this.oTextControl.write(); this.oTooltip.hide(); this.recheckParagraph(iParaNum); + this.iLastEditedParagraph = iParaNum; } catch (e) { showError(e); } }