Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiple calls to the update function #21

Closed
peterprvy opened this issue Feb 22, 2023 · 3 comments
Closed

multiple calls to the update function #21

peterprvy opened this issue Feb 22, 2023 · 3 comments
Assignees

Comments

@peterprvy
Copy link

Sorry, my english is bad (I use a translator)

When the text in the textarea is changed, the update function is called in oninput

in it, setting the value causes an update again (in the attributeChangedCallback function)

        /* Syntax-highlighting functions */
        update(text) {
            if(this.value != text) this.value = text; // Change value attribute if necessary.
            if(this.querySelector("textarea").value != text) this.querySelector("textarea").value = text; 

assignment this.value = text; generate attributeChangedCallback

        attributeChangedCallback(name, oldValue, newValue) {
            if(this.isConnected) {
                // This will sometimes be called before the element has been created, so trying to update an attribute causes an error.
                // Thanks to Kevin Loughead for pointing this out.
                
                this.plugin_evt("attributeChanged", [name, oldValue, newValue]); // Plugin event
                switch (name) {
    
                    case "value":
    
                        // Update code
                        this.update(newValue);
@peterprvy
Copy link
Author

My solution:

        /* Syntax-highlighting functions */
        update(text) {
            if(this.value != text) {
                this._inUpdateNewText = text;
                this.value = text; // Change value attribute if necessary.
                this._inUpdateNewText = undefined;
            }
            if(this.querySelector("textarea").value != text) this.querySelector("textarea").value = text; 

        
        attributeChangedCallback(name, oldValue, newValue) {
            if(this.isConnected) {
                // This will sometimes be called before the element has been created, so trying to update an attribute causes an error.
                // Thanks to Kevin Loughead for pointing this out.
                
                this.plugin_evt("attributeChanged", [name, oldValue, newValue]); // Plugin event
                switch (name) {
    
                    case "value":
    
                        // Update code
                        if(this._inUpdateNewText === undefined || newValue !== this._inUpdateNewText) {
                            this.update(newValue); 
                        }
        
                        break;

@WebCoder49
Copy link
Owner

Thank you for this. I will add your solution to the code as soon as possible.

@WebCoder49 WebCoder49 self-assigned this Mar 10, 2023
@WebCoder49
Copy link
Owner

I have committed this now, and should release it in the next release. Thank you again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants