File tree Expand file tree Collapse file tree 1 file changed +16
-6
lines changed
Expand file tree Collapse file tree 1 file changed +16
-6
lines changed Original file line number Diff line number Diff line change @@ -66,10 +66,18 @@ var codeInput = {
6666 }
6767 }
6868
69- /* Syntax-highlighting functions */
70- update ( text ) {
71- if ( this . value != text ) this . value = text ; // Change value attribute if necessary.
72- if ( this . querySelector ( "textarea" ) . value != text ) this . querySelector ( "textarea" ) . value = text ;
69+ /* Syntax-highlighting functions */
70+ update ( text ) {
71+ console . log ( "Update" , text ) ;
72+
73+ // Prevent this from running multiple times on the same input when "value" attribute is changed,
74+ // by saving the value currently updated as _inUpdateNewText. Thank you to peterprvy for this.
75+ if ( this . value != text ) {
76+ this . _inUpdateNewText = text ;
77+ this . value = text ; // Change value attribute if necessary.
78+ this . _inUpdateNewText = undefined ;
79+ }
80+ if ( this . querySelector ( "textarea" ) . value != text ) this . querySelector ( "textarea" ) . value = text ;
7381
7482
7583 let result_element = this . querySelector ( "pre code" ) ;
@@ -199,8 +207,10 @@ var codeInput = {
199207
200208 case "value" :
201209
202- // Update code
203- this . update ( newValue ) ;
210+ // Update code, only if this text has not already been updated.
211+ if ( this . _inUpdateNewText === undefined || newValue !== this . _inUpdateNewText ) {
212+ this . update ( newValue ) ;
213+ }
204214
205215 break ;
206216
You can’t perform that action at this time.
0 commit comments