Skip to content

Commit 9eb33b6

Browse files
authored
Merge pull request #229 from WebCoder49/multiple-attributes-changed
Fix bugs and add test for `language` attribute (Fixes #228)
2 parents 352744d + 86f00b9 commit 9eb33b6

2 files changed

Lines changed: 29 additions & 4 deletions

File tree

code-input.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -986,16 +986,16 @@ var codeInput = {
986986
/* Check regular attributes */
987987
for(let i = 0; i < codeInput.observedAttributes.length; i++) {
988988
if (mutation.attributeName == codeInput.observedAttributes[i]) {
989-
return this.attributeChangedCallback(mutation.attributeName, mutation.oldValue, super.getAttribute(mutation.attributeName));
989+
this.attributeChangedCallback(mutation.attributeName, mutation.oldValue, super.getAttribute(mutation.attributeName));
990990
}
991991
}
992992
for(let i = 0; i < codeInput.textareaSyncAttributes.length; i++) {
993993
if (mutation.attributeName == codeInput.textareaSyncAttributes[i]) {
994-
return this.attributeChangedCallback(mutation.attributeName, mutation.oldValue, super.getAttribute(mutation.attributeName));
994+
this.attributeChangedCallback(mutation.attributeName, mutation.oldValue, super.getAttribute(mutation.attributeName));
995995
}
996996
}
997997
if (mutation.attributeName.substring(0, 5) == "aria-") {
998-
return this.attributeChangedCallback(mutation.attributeName, mutation.oldValue, super.getAttribute(mutation.attributeName));
998+
this.attributeChangedCallback(mutation.attributeName, mutation.oldValue, super.getAttribute(mutation.attributeName));
999999
}
10001000
}
10011001
}
@@ -1059,7 +1059,13 @@ var codeInput = {
10591059
}
10601060

10611061
if (mainTextarea.placeholder == oldValue || oldValue == null && mainTextarea.placeholder == "") {
1062-
mainTextarea.placeholder = newValue;
1062+
if(newValue === null) {
1063+
mainTextarea.removeAttribute("placeholder");
1064+
// If always setAttribute, would set it to the string
1065+
// "null" here, which isn't wanted.'
1066+
} else {
1067+
mainTextarea.setAttribute("placeholder", newValue);
1068+
}
10631069
}
10641070

10651071
this.scheduleHighlight();

tests/tester.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,25 @@ console.log("I've got another line!", 2 &lt; 3, "should be true.");
491491

492492
codeInputElement.style.removeProperty("caret-color");
493493

494+
if(!isHLJS) {
495+
// These tests require autodetect plugin to be absent
496+
497+
codeInputElement.setAttribute("language", "css");
498+
await waitAsync(50); // Wait for language to propogate to class
499+
testAssertion("Core", "Language Class Propogates", codeInputElement.querySelector("pre").classList.contains("language-css"), `Class name of pre element was "${codeInputElement.querySelector("pre").className}" but code-input element had language="css"`);
500+
501+
window.requestAnimationFrame(function() {
502+
codeInputElement.setAttribute("placeholder", "Gimme some HTML!");
503+
codeInputElement.setAttribute("language", "html");
504+
});
505+
await waitAsync(500); // Wait for animation frame; language to propogate to class
506+
testAssertion("Core", "Language Class Propogates When Set Immediately After Placeholder Set", codeInputElement.querySelector("pre").classList.contains("language-html"), `Class name of pre element was "${codeInputElement.querySelector("pre").className}" but code-input element had language="css"`);
507+
508+
codeInputElement.removeAttribute("placeholder");
509+
codeInputElement.setAttribute("language", "JavaScript");
510+
await waitAsync(50); // Wait for language to propogate to class
511+
}
512+
494513
/*--- Tests for plugins ---*/
495514
// AutoCloseBrackets
496515
testAddingText("AutoCloseBrackets", textarea, function(textarea) {

0 commit comments

Comments
 (0)