Grammalecte  Diff

Differences From Artifact [cf017aaf08]:

To Artifact [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);
        }
    }
}