Grammalecte  Diff

Differences From Artifact [1c3cef7a06]:

To Artifact [327f3b8b3c]:


135
136
137
138
139
140
141
142
143
144

145
146
147
148
149
150
151
        this.xMenu.appendChild(this.xTFButton)
        this.xMenu.appendChild(this.xEditorButton)
        this.xMenu.appendChild(this.xLxgButton)
        this.xMenu.appendChild(this.xConjButton)
        this.xPanelBar.appendChild(this.xMenu);
    }

    start (what) {
        this.oTooltip.hide();
        this.bWorking = false;

        this.clear();
        this.hideMessage();
        this.resetTimer();
        if (typeof(what) === "string") {
            // text
            this.xNode = null;
            this.oTextControl.setText(what);







|


>







135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
        this.xMenu.appendChild(this.xTFButton)
        this.xMenu.appendChild(this.xEditorButton)
        this.xMenu.appendChild(this.xLxgButton)
        this.xMenu.appendChild(this.xConjButton)
        this.xPanelBar.appendChild(this.xMenu);
    }

    start (what, bResultInEvent=false) {
        this.oTooltip.hide();
        this.bWorking = false;
        this.oTextControl.bResultInEvent = bResultInEvent;
        this.clear();
        this.hideMessage();
        this.resetTimer();
        if (typeof(what) === "string") {
            // text
            this.xNode = null;
            this.oTextControl.setText(what);
950
951
952
953
954
955
956

957
958
959
960
961
962
963

class GrammalecteTextControl {

    constructor () {
        this.xNode = null;
        this.dParagraph = new Map();
        this.bTextArea = null;

    }

    setNode (xNode) {
        this.clear();
        this.xNode = xNode;
        this.bTextArea = (xNode.tagName == "TEXTAREA" || xNode.tagName == "INPUT");
        if (!this.bTextArea) {







>







951
952
953
954
955
956
957
958
959
960
961
962
963
964
965

class GrammalecteTextControl {

    constructor () {
        this.xNode = null;
        this.dParagraph = new Map();
        this.bTextArea = null;
        this.bResultInEvent = false; // if true, the node content is not modified, but an event is dispatched on the node with the modified text
    }

    setNode (xNode) {
        this.clear();
        this.xNode = xNode;
        this.bTextArea = (xNode.tagName == "TEXTAREA" || xNode.tagName == "INPUT");
        if (!this.bTextArea) {
1015
1016
1017
1018
1019
1020
1021







1022
1023

1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
        while (this.xNode.firstChild) {
            this.xNode.removeChild(this.xNode.firstChild);
        }
    }

    write () {
        if (this.xNode !== null) {







            if (this.bTextArea) {
                this.xNode.value = this.getText();

            } else {
                this.eraseNodeContent();
                this.dParagraph.forEach((val, key) => {
                    this.xNode.appendChild(document.createTextNode(val.normalize("NFC")));
                    this.xNode.appendChild(document.createElement("br"));
                });
                const xEvent = new CustomEvent("grammalecteNodeContentUpdated", {
                    detail: { text: [...this.dParagraph.values()].join("\n").normalize("NFC") }
                });
                this.xNode.dispatchEvent(xEvent);
            }
        }
    }
}







>
>
>
>
>
>
>
|

>
|





<
<
<
<




1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039




1040
1041
1042
1043
        while (this.xNode.firstChild) {
            this.xNode.removeChild(this.xNode.firstChild);
        }
    }

    write () {
        if (this.xNode !== null) {
            if (this.bResultInEvent) {
                const xEvent = new CustomEvent("GrammalecteNodeContentUpdated", {
                    detail: { text: [...this.dParagraph.values()].join("\n").normalize("NFC") }
                });
                this.xNode.dispatchEvent(xEvent);
                console.log("event", xEvent.detail.text);
            }
            else if (this.bTextArea) {
                this.xNode.value = this.getText();
            }
            else {
                this.eraseNodeContent();
                this.dParagraph.forEach((val, key) => {
                    this.xNode.appendChild(document.createTextNode(val.normalize("NFC")));
                    this.xNode.appendChild(document.createElement("br"));
                });




            }
        }
    }
}