Index: gc_lang/fr/webext/background.js ================================================================== --- gc_lang/fr/webext/background.js +++ gc_lang/fr/webext/background.js @@ -340,12 +340,10 @@ // Tools browser.contextMenus.create({ id: "conjugueur_tab", title: "Conjugueur [onglet]", contexts: ["all"] }); browser.contextMenus.create({ id: "conjugueur_window", title: "Conjugueur [fenêtre]", contexts: ["all"] }); //browser.contextMenus.create({ id: "dictionaries", title: "Dictionnaires", contexts: ["all"] }); browser.contextMenus.create({ id: "lexicon_editor", title: "Éditeur lexical", contexts: ["all"] }); -// Rescan page -browser.contextMenus.create({ id: "separator_rescan", type: "separator", contexts: ["editable"] }); browser.contextMenus.onClicked.addListener(function (xInfo, xTab) { // xInfo = https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/contextMenus/OnClickData // xTab = https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/tabs/Tab Index: gc_lang/fr/webext/content_scripts/init.js ================================================================== --- gc_lang/fr/webext/content_scripts/init.js +++ gc_lang/fr/webext/content_scripts/init.js @@ -172,10 +172,23 @@ } catch (e) { showError(e); } }, + + findOriginEditableNode: function (xNode) { + if (!xNode) { + return null; + } + if (xNode.tagName == "TEXTAREA" || xNode.tagName == "INPUT" || xNode.tagName == "IFRAME") { + return xNode; + } + const findNode = function (xNode) { + return (!xNode.parentNode.isContentEditable) ? xNode : findNode(xNode.parentNode); + } + return findNode(xNode); + }, getCaretPosition: function (xElement) { // JS awfulness again. // recepie from https://stackoverflow.com/questions/4811822/get-a-ranges-start-and-end-offsets-relative-to-its-parent-container let nCaretOffsetStart = 0; @@ -276,10 +289,17 @@ sCommand: the action to perform oParam: parameters necessary for the execution of the action oInfo: all kind of informations that needs to be sent back (usually to know where to use the result) } */ + + checkConnection: function () { + if (!this.xConnect) { + this.xConnect = browser.runtime.connect({name: "content-script port"}); + } + }, + parseAndSpellcheck: function (sText, sDestination) { this.xConnect.postMessage({ sCommand: "parseAndSpellcheck", oParam: { sText: sText, sCountry: "FR", bDebug: false, bContext: false }, oInfo: { sDestination: sDestination } @@ -398,11 +418,12 @@ (Context menu are initialized in background) */ // Grammar checker commands case "grammar_checker_editable": if (oGrammalecte.xRightClickedNode !== null) { - oGrammalecte.startGCPanel(oGrammalecte.xRightClickedNode); + let xNode = oGrammalecte.findOriginEditableNode(oGrammalecte.xRightClickedNode); + oGrammalecte.startGCPanel(xNode); } else { oGrammalecte.showMessage("Erreur. Le node sur lequel vous avez cliqué n’a pas pu être identifié. Sélectionnez le texte à corriger et relancez le correcteur via le menu contextuel."); } break; case "grammar_checker_page": @@ -430,11 +451,11 @@ Other messages from background */ listen2: function () { browser.runtime.onMessage.addListener(function (oMessage) { let {sActionRequest} = oMessage; - let xActiveNode = document.activeElement; + let xActiveNode = oGrammalecte.findOriginEditableNode(document.activeElement); switch (sActionRequest) { /* Commands received from the keyboard (shortcuts) */ case "shortcutGrammarChecker": 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 @@ -54,14 +54,11 @@ // textarea or iframe this.accept(xNode) } else if (xNode.isContentEditable && this._bEditableNode) { // editable node - const findOriginEditableNode = function (xNode) { - return (!xNode.parentNode.isContentEditable) ? xNode : findOriginEditableNode(xNode.parentNode); - } - xNode = findOriginEditableNode(xNode); + xNode = oGrammalecte.findOriginEditableNode(xNode); if ((xNode.tagName == "P" || xNode.tagName == "DIV") && !(xNode.dataset.grammalecte_button && xNode.dataset.grammalecte_button == "false")) { this.accept(xNode); } else { this.reject(); }