Grammalecte  Check-in [90fe38d829]

Overview
Comment:[fx] move button when text area is resized, gc panel: prevent recheckParagraph when closed
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | fx
Files: files | file ages | folders
SHA3-256: 90fe38d829aca1919e083b76af870e69981aef2a9e78e3ea80fe63a28a52571d
User & Date: olr on 2020-04-07 22:23:43
Original Comment: [fx] move button when text area is resized
Other Links: manifest | tags
Context
2020-04-08
07:31
[fr] ajustements check-in: 651318a215 user: olr tags: fr, trunk
2020-04-07
22:23
[fx] move button when text area is resized, gc panel: prevent recheckParagraph when closed check-in: 90fe38d829 user: olr tags: fx, trunk
22:21
[fr] faux positif et ajustements check-in: 26c9bbaed1 user: olr tags: fr, trunk
Changes

Modified gc_lang/fr/webext/content_scripts/menu.js from [562aee0f70] to [f330b67949].

     1      1   // JavaScript
     2      2   
     3      3   /* jshint esversion:6, -W097 */
     4      4   /* jslint esversion:6 */
     5      5   /* global oGrammalecte, showError, window, document */
     6      6   
     7      7   "use strict";
            8  +
     8      9   
     9     10   class GrammalecteButton {
    10     11   
    11     12       constructor () {
    12     13           // the pearl button
    13     14           this.xButton = oGrammalecte.createNode("div", { className: "grammalecte_menu_main_button", textContent: " " });
    14     15           this.xButton.onclick = () => {
................................................................................
    35     36               this._bEditableNode = oOptions.ui_options.editablenode;
    36     37           }
    37     38       }
    38     39   
    39     40       examineNode (xNode) {
    40     41           if (xNode && xNode instanceof HTMLElement) {
    41     42               if (xNode === this.xTextNode) {
           43  +                this.move();
    42     44                   return;
    43     45               }
    44     46               if ( ( (xNode.tagName == "TEXTAREA" && this._bTextArea && xNode.getAttribute("spellcheck") !== "false")
    45     47                       || (xNode.isContentEditable && this._bEditableNode)
    46     48                       || (xNode.tagName == "IFRAME" && this._bIframe) )
    47     49                       && xNode.style.display !== "none" && xNode.style.visibility !== "hidden"
    48     50                       && !(xNode.dataset.grammalecte_button  &&  xNode.dataset.grammalecte_button == "false") ) {
    49     51                   this.xTextNode = xNode;
    50     52                   this.show()
    51     53               }
           54  +            else {
           55  +                this.xTextNode = null;
           56  +                this.hide();
           57  +            }
    52     58           }
    53     59           else {
    54     60               this.xTextNode = null;
    55     61               this.hide();
    56     62           }
    57     63       }
    58     64   
    59     65       show () {
    60     66           if (this.xTextNode) {
    61     67               this.xButton.style.display = "none"; // we hide it before showing it again to relaunch the animation
    62         -            let oCoord = oGrammalecte.getElementCoord(this.xTextNode);
    63         -            //console.log("top:", oCoord.left, "bottom:", oCoord.top, "left:", oCoord.bottom, "right:", oCoord.right);
    64         -            this.xButton.style.top = `${oCoord.bottom}px`;
    65         -            this.xButton.style.left = `${oCoord.left}px`;
           68  +            this.move();
    66     69               this.xButton.style.display = "block";
    67     70           }
    68     71       }
    69     72   
    70     73       hide () {
    71     74           this.xButton.style.display = "none";
    72     75       }
           76  +
           77  +    move () {
           78  +        if (this.xTextNode) {
           79  +            let oCoord = oGrammalecte.getElementCoord(this.xTextNode);
           80  +            this.xButton.style.top = `${oCoord.bottom}px`;
           81  +            this.xButton.style.left = `${oCoord.left}px`;
           82  +        }
           83  +    }
    73     84   
    74     85       insertIntoPage () {
    75     86           this.bShadow = document.body.createShadowRoot || document.body.attachShadow;
    76     87           if (this.bShadow) {
    77     88               this.xShadowBtn = oGrammalecte.createNode("div", { style: "display:none; position:absolute; width:0; height:0;" });
    78     89               this.xShadowBtnNode = this.xShadowBtn.attachShadow({ mode: "open" });
    79     90               oGrammalecte.createStyle("content_scripts/menu.css", null, this.xShadowBtnNode);

Modified gc_lang/fr/webext/content_scripts/panel.js from [98261d40f5] to [8de62f65f5].

    15     15           this.nWidth = nWidth;
    16     16           this.nHeight = nHeight;
    17     17           this.bFlexible = bFlexible;
    18     18           this.bHorizStrech = false;
    19     19           this.bVertStrech = false;
    20     20           this.nPositionX = 2;
    21     21           this.nPositionY = 2;
           22  +        this.bOpened = false;
    22     23           this.bWorking = false;
    23     24   
    24     25           this.bShadow = document.body.createShadowRoot || document.body.attachShadow;
    25     26           if (this.bShadow) {
    26     27               this.xShadowPanel = oGrammalecte.createNode("div", {id: this.sId+"_shadow", style: "width:0;height:0;"});
    27     28               this.xShadow = this.xShadowPanel.attachShadow({mode: "open"});
    28     29               this.xParent = this.xShadow;
................................................................................
   140    141               }
   141    142               document.body.appendChild(this.xPanel);
   142    143           }
   143    144       }
   144    145   
   145    146       show () {
   146    147           this.xPanel.style.display = "flex";
          148  +        this.bOpened = true;
   147    149       }
   148    150   
   149    151       hide () {
   150    152           this.xPanel.style.display = "none";
          153  +        this.bOpened = false;
   151    154       }
   152    155   
   153    156       center () {
   154    157           this.nPosition = 5;
   155    158           this.setSizeAndPosition();
   156    159       }
   157    160   

Modified gc_lang/fr/webext/content_scripts/panel_gc.js from [e6011e0390] to [ec198a43f7].

   271    271       }
   272    272   
   273    273       endTimer () {
   274    274           window.clearTimeout(this.nTimer);
   275    275       }
   276    276   
   277    277       recheckParagraph (iParaNum) {
          278  +        if (!this.bOpened) {
          279  +            return;
          280  +        }
   278    281           let sParagraphId = "grammalecte_paragraph" + iParaNum;
   279    282           let xParagraph = this.xParent.getElementById(sParagraphId);
   280    283           this._blockParagraph(xParagraph);
   281    284           let sText = this.purgeText(xParagraph.textContent);
   282    285           oGrammalecteBackgroundPort.parseAndSpellcheck1(sText, "__GrammalectePanel__", sParagraphId);
   283    286           this.oTextControl.setParagraph(iParaNum, sText);
   284    287           this.oTextControl.write();
   285    288       }
   286    289   
   287    290       refreshParagraph (sParagraphId, oResult) {
   288    291           // function called when results are sent by the Worker
          292  +        if (!this.bOpened) {
          293  +            return;
          294  +        }
   289    295           try {
   290    296               let xParagraph = this.xParent.getElementById(sParagraphId);
   291    297               // save caret position
   292    298               let [nStart, nEnd] = oGrammalecte.getCaretPosition(xParagraph);
   293    299               xParagraph.dataset.caret_position_start = nStart;
   294    300               xParagraph.dataset.caret_position_end = nEnd;
   295    301               // erase texte
................................................................................
  1036   1042       }
  1037   1043   
  1038   1044       write () {
  1039   1045           if (this.xNode !== null) {
  1040   1046               if (this.bResultInEvent) {
  1041   1047                   const xEvent = new CustomEvent("GrammalecteResult", { detail: JSON.stringify({ sType: "text", sText: this.getText() }) });
  1042   1048                   this.xNode.dispatchEvent(xEvent);
  1043         -                //console.log("Text to xNode:", xEvent.detail);
         1049  +                console.log("[Grammalecte debug] Text sent to xNode via event:", xEvent.detail);
  1044   1050               }
  1045   1051               else if (this.bTextArea) {
  1046   1052                   this.xNode.value = this.getText();
         1053  +                console.log("[Grammalecte debug] text written in textarea:", this.getText());
  1047   1054               }
  1048   1055               else if (this.bIframe) {
  1049   1056                   //console.log(this.getText());
  1050   1057               }
  1051   1058               else {
         1059  +                let sText = "";
  1052   1060                   this.eraseNodeContent();
  1053   1061                   this.dParagraph.forEach((val, key) => {
  1054   1062                       this.xNode.appendChild(document.createTextNode(val.normalize("NFC")));
  1055   1063                       this.xNode.appendChild(document.createElement("br"));
         1064  +                    sText += val.normalize("NFC") + "\n";
  1056   1065                   });
         1066  +                console.log("[Grammalecte debug] text written in editable node:", sText);
  1057   1067               }
  1058   1068           }
  1059   1069           else if (this.xResultNode !== null) {
  1060   1070               const xEvent = new CustomEvent("GrammalecteResult", { detail: JSON.stringify({ sType: "text", sText: this.getText() }) });
  1061   1071               this.xResultNode.dispatchEvent(xEvent);
  1062         -            //console.log("Text to xResultNode:", xEvent.detail);
         1072  +            console.log("[Grammalecte debug] Text sent to xResultNode via event:", xEvent.detail);
  1063   1073           }
  1064   1074       }
  1065   1075   }