Grammalecte  Check-in [3d4e5a9e46]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:[fx][bug?] copy text to clipboard
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | fx
Files: files | file ages | folders
SHA3-256:3d4e5a9e46349fb73096c1efcd18f0f2761c24c5181f2847c82a41461a88d4a2
User & Date: olr 2019-05-12 18:33:04
Context
2019-05-12
18:57
[fx] update manifest.json check-in: 49d3639117 user: olr tags: fx, trunk
18:33
[fx][bug?] copy text to clipboard check-in: 3d4e5a9e46 user: olr tags: fx, trunk
17:00
[fr] faux positif check-in: a82ca1439e user: olr tags: fr, trunk
Changes

Changes to gc_lang/fr/webext/content_scripts/init.js.

   221    221               }
   222    222               return xNode;
   223    223           }
   224    224           catch (e) {
   225    225               showError(e);
   226    226           }
   227    227       },
          228  +
          229  +    sendTextToClipboard (sText)  {
          230  +        // recipe from https://github.com/mdn/webextensions-examples/blob/master/context-menu-copy-link-with-types/clipboard-helper.js
          231  +        // It doesn’t seem to work anymore
          232  +        //console.log(sText);
          233  +        function setClipboardData (xEvent) {
          234  +            document.removeEventListener("copy", setClipboardData, true);
          235  +            xEvent.stopImmediatePropagation();
          236  +            xEvent.preventDefault();
          237  +            xEvent.clipboardData.setData("text/plain", sText);
          238  +        }
          239  +        document.addEventListener("copy", setClipboardData, true);
          240  +        document.execCommand("copy");
          241  +    },
   228    242   
   229    243       getCaretPosition (xElement) {
   230    244           // JS awfulness again.
   231    245           // recepie from https://stackoverflow.com/questions/4811822/get-a-ranges-start-and-end-offsets-relative-to-its-parent-container
   232    246           let nCaretOffsetStart = 0;
   233    247           let nCaretOffsetEnd = 0;
   234    248           let xSelection = window.getSelection();

Changes to gc_lang/fr/webext/content_scripts/panel_gc.js.

   382    382       }
   383    383   
   384    384       addMessageToGCPanel (sMessage) {
   385    385           let xNode = oGrammalecte.createNode("div", {className: "grammalecte_panel_flow_message", textContent: sMessage});
   386    386           this.xParagraphList.appendChild(xNode);
   387    387       }
   388    388   
   389         -    _copyToClipboard (sText)  {
   390         -        // recipe from https://github.com/mdn/webextensions-examples/blob/master/context-menu-copy-link-with-types/clipboard-helper.js
   391         -        function setClipboardData (xEvent) {
   392         -            document.removeEventListener("copy", setClipboardData, true);
   393         -            xEvent.stopImmediatePropagation();
   394         -            xEvent.preventDefault();
   395         -            xEvent.clipboardData.setData("text/plain", sText);
   396         -        }
   397         -        document.addEventListener("copy", setClipboardData, true);
   398         -        document.execCommand("copy");
   399         -    }
   400         -
   401    389       copyTextToClipboard () {
   402    390           this.startWaitIcon();
   403    391           try {
   404    392               let xClipboardButton = this.xParent.getElementById("grammalecte_clipboard_button");
   405    393               xClipboardButton.textContent = "⇒ presse-papiers";
   406    394               let sText = "";
   407    395               // Quand c'est dans un shadow "this.xParent.getElementsByClassName" n'existe pas.
   408    396               let xElem = this.xParent.getElementById("grammalecte_gc_panel");
   409    397               for (let xNode of xElem.getElementsByClassName("grammalecte_paragraph")) {
   410    398                   sText += xNode.textContent + "\n";
   411    399               }
   412         -            this._copyToClipboard(sText);
          400  +            oGrammalecte.sendTextToClipboard(sText);
   413    401               window.setTimeout(() => { xClipboardButton.textContent = "📋"; }, 2000);
   414    402           }
   415    403           catch (e) {
   416    404               showError(e);
   417    405           }
   418    406           this.stopWaitIcon();
   419    407       }