Grammalecte  Check-in [72fe2a6c07]

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

Overview
Comment:[fx] fix caret position saving
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | fx
Files: files | file ages | folders
SHA3-256:72fe2a6c07ac9ffad725ccb78777e69e25d050653be4fc481549b4c2f78f66e6
User & Date: olr 2019-08-10 15:33:41
Context
2019-08-10
16:55
[fx] autorefresh option check-in: 5539a3d29b user: olr tags: fx, trunk
15:33
[fx] fix caret position saving check-in: 72fe2a6c07 user: olr tags: fx, trunk
12:35
[fr] fix regex check-in: ea1eaff896 user: olr tags: fr, trunk
Changes

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

   235    235                   xParagraph.setAttribute("spellcheck", "false"); // doesn’t seem possible to use “spellcheck” as a common attribute.
   236    236                   xParagraph.dataset.timer_id = "0";
   237    237                   xParagraph.addEventListener("input", function (xEvent) {
   238    238                       if (this.bAutoRefresh) {
   239    239                           // timer for refreshing analysis
   240    240                           window.clearTimeout(parseInt(xParagraph.dataset.timer_id, 10));
   241    241                           xParagraph.dataset.timer_id = window.setTimeout(this.recheckParagraph.bind(this), 3000, oResult.iParaNum);
   242         -                        // save caret position
   243         -                        let [nStart, nEnd] = oGrammalecte.getCaretPosition(xParagraph);
   244         -                        xParagraph.dataset.caret_position_start = nStart;
   245         -                        xParagraph.dataset.caret_position_end = nEnd;
   246    242                       }
   247    243                       // write text
   248    244                       this.oTextControl.setParagraph(parseInt(xEvent.target.dataset.para_num, 10), this.purgeText(xEvent.target.textContent));
   249    245                       this.oTextControl.write();
   250    246                   }.bind(this)
   251    247                   , true);
   252         -                /*xParagraph.addEventListener("blur", function (xEvent) {
   253         -                    // remove timer for refreshing analysis
   254         -                    window.clearTimeout(parseInt(xParagraph.dataset.timer_id));
   255         -                    // unset caret position
   256         -                    xParagraph.dataset.caret_position_start = "-1";
   257         -                    xParagraph.dataset.caret_position_end = "-1";
   258         -                    // recheck
   259         -                    this.recheckParagraph(oResult.iParaNum);
   260         -                }.bind(this)
   261         -                , true);*/
   262    248                   this._tagParagraph(xParagraph, oResult.sParagraph, oResult.iParaNum, oResult.aGrammErr, oResult.aSpellErr);
   263    249                   // creation
   264    250                   xNodeDiv.appendChild(xActionsBar);
   265    251                   xNodeDiv.appendChild(xParagraph);
   266    252                   this.xParagraphList.appendChild(xNodeDiv);
   267    253               }
   268    254           }
................................................................................
   286    272       endTimer () {
   287    273           window.clearTimeout(this.nTimer);
   288    274       }
   289    275   
   290    276       recheckParagraph (iParaNum) {
   291    277           let sParagraphId = "grammalecte_paragraph" + iParaNum;
   292    278           let xParagraph = this.xParent.getElementById(sParagraphId);
   293         -        this.blockParagraph(xParagraph);
          279  +        this._blockParagraph(xParagraph);
   294    280           let sText = this.purgeText(xParagraph.textContent);
   295    281           xGrammalectePort.postMessage({
   296    282               sCommand: "parseAndSpellcheck1",
   297    283               dParam: {sText: sText, sCountry: "FR", bDebug: false, bContext: false},
   298    284               dInfo: {sParagraphId: sParagraphId}
   299    285           });
   300    286           this.oTextControl.setParagraph(iParaNum, sText);
................................................................................
   301    287           this.oTextControl.write();
   302    288       }
   303    289   
   304    290       refreshParagraph (sParagraphId, oResult) {
   305    291           // function called when results are sent by the Worker
   306    292           try {
   307    293               let xParagraph = this.xParent.getElementById(sParagraphId);
   308         -            xParagraph.className = (oResult.aGrammErr.length || oResult.aSpellErr.length) ? "grammalecte_paragraph softred" : "grammalecte_paragraph";
          294  +            // save caret position
          295  +            let [nStart, nEnd] = oGrammalecte.getCaretPosition(xParagraph);
          296  +            xParagraph.dataset.caret_position_start = nStart;
          297  +            xParagraph.dataset.caret_position_end = nEnd;
          298  +            // erase texte
   309    299               xParagraph.textContent = "";
          300  +            // recreate and retag
   310    301               this._tagParagraph(xParagraph, oResult.sParagraph, sParagraphId.slice(21), oResult.aGrammErr, oResult.aSpellErr);
   311         -            this.freeParagraph(xParagraph);
          302  +            this._freeParagraph(xParagraph);
   312    303           }
   313    304           catch (e) {
   314    305               showError(e);
   315    306           }
   316    307       }
   317    308   
   318    309       _tagParagraph (xParagraph, sParagraph, iParaNum, aSpellErr, aGrammErr) {
................................................................................
   371    362               xNodeErr.dataset.suggestions = oErr["aSuggestions"].join("|");
   372    363           }
   373    364           xNodeErr.className = (this.aIgnoredErrors.has(xNodeErr.dataset.ignored_key)) ? "grammalecte_error_ignored" : "grammalecte_error";
   374    365           xNodeErr.style.backgroundColor = (oErr['sType'] === "WORD") ? "hsl(0, 50%, 50%)" : oErr["aColor"];
   375    366           return xNodeErr;
   376    367       }
   377    368   
   378         -    blockParagraph (xParagraph) {
          369  +    _blockParagraph (xParagraph) {
   379    370           xParagraph.contentEditable = "false";
   380    371           this.xParent.getElementById("grammalecte_check"+xParagraph.dataset.para_num).textContent = "!!";
   381    372           this.xParent.getElementById("grammalecte_check"+xParagraph.dataset.para_num).style.backgroundColor = "hsl(0, 50%, 50%)";
   382    373           this.xParent.getElementById("grammalecte_check"+xParagraph.dataset.para_num).style.boxShadow = "0 0 0 3px hsla(0, 0%, 50%, .2)";
   383    374           this.xParent.getElementById("grammalecte_check"+xParagraph.dataset.para_num).style.animation = "grammalecte-pulse 1s linear infinite";
   384    375       }
   385    376   
   386         -    freeParagraph (xParagraph) {
          377  +    _freeParagraph (xParagraph) {
   387    378           xParagraph.contentEditable = "true";
   388    379           if (xParagraph.dataset.caret_position_start !== "-1") {
   389    380               let nStart = parseInt(xParagraph.dataset.caret_position_start, 10);
   390    381               let nEnd = parseInt(xParagraph.dataset.caret_position_end, 10);
   391    382               oGrammalecte.setCaretPosition(xParagraph, nStart, nEnd);
   392    383           }
   393    384           this.xParent.getElementById("grammalecte_check"+xParagraph.dataset.para_num).textContent = "↻";