Grammalecte  Check-in [9002c7508c]

Overview
Comment:[fx] object to control textarea
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | fx | webext2
Files: files | file ages | folders
SHA3-256: 9002c7508c066474854ae7446390a207523ef92483afcbe1d9e1131d9f1b0906
User & Date: olr on 2017-08-16 18:27:30
Other Links: branch diff | manifest | tags
Context
2017-08-22
08:02
[fx] textarea control + small code refactoring check-in: 40e9aa097d user: olr tags: fx, webext2
2017-08-16
18:27
[fx] object to control textarea check-in: 9002c7508c user: olr tags: fx, webext2
16:00
[fx] CSS adjustments check-in: 1d184c21b2 user: olr tags: fx, webext2
Changes

Modified gc_lang/fr/webext/content_scripts/gc_content.js from [cf017aaf08] to [869a446e62].

366
367
368
369
370
371
372




























































            }
        }
        catch (e) {
            showError(e);
        }
    }
}



































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
            }
        }
        catch (e) {
            showError(e);
        }
    }
}


const oGrammalecteTextareaControl = {

    xTextarea: null,

    dParagraph: new Map(),

    setTextarea: function (xNode) {
        this.xTextarea = xNode;
        this.xTextarea.disabled = true;
    },

    clear: function () {
        this.xTextarea.disabled = false;
        this.xTextarea = null;
        this.dParagraph.clear();
    },

    setParagraph (iParagraph, sText) {
        this.dParagraph.set(iParagraph, sText);
    },

    getParagraph (iParagraph) {
        return dParagraphs.has(iParagraph) ? this.dParagraphs.get(iParagraph) : this.getNthParagraph(iParagraph);
    },

    getNthParagraph: function (iParagraph) {
        if (this.xTextarea !== null) {
            let sText = this.xTextarea.value;
            let i = 0;
            let iStart = 0;
            while (i < iParagraph && ((iStart = sText.indexOf("\n", iStart)) !== -1)) {
                i++;
                iStart++;
            }
            if (i === iParagraph) {
                return ((iEnd = sText.indexOf("\n", iStart)) !== -1) ? sText.slice(iStart, iEnd) : sText.slice(iStart);
            }
            return "# Erreur. Paragraphe introuvable.";
        }
        return "# Erreur. Zone de texte introuvable.";
    },

    rewrite: function () {
        try {
            if (this.xTextarea !== null) {
                let sText = "";
                let i = 0;
                for (let sParagraph of this.xTextarea.value.split("\n")) {
                    sText += (dParagraphs.has(i)) ? dParagraphs.get(i) + "\n" : sParagraph + "\n";
                    i += 1;
                }
                this.xTextarea.value = sText.slice(0,-1);
            }
        } catch (e) {
            showError(e);
        }
    }
}