Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions code-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -986,16 +986,16 @@ var codeInput = {
/* Check regular attributes */
for(let i = 0; i < codeInput.observedAttributes.length; i++) {
if (mutation.attributeName == codeInput.observedAttributes[i]) {
return this.attributeChangedCallback(mutation.attributeName, mutation.oldValue, super.getAttribute(mutation.attributeName));
this.attributeChangedCallback(mutation.attributeName, mutation.oldValue, super.getAttribute(mutation.attributeName));
}
}
for(let i = 0; i < codeInput.textareaSyncAttributes.length; i++) {
if (mutation.attributeName == codeInput.textareaSyncAttributes[i]) {
return this.attributeChangedCallback(mutation.attributeName, mutation.oldValue, super.getAttribute(mutation.attributeName));
this.attributeChangedCallback(mutation.attributeName, mutation.oldValue, super.getAttribute(mutation.attributeName));
}
}
if (mutation.attributeName.substring(0, 5) == "aria-") {
return this.attributeChangedCallback(mutation.attributeName, mutation.oldValue, super.getAttribute(mutation.attributeName));
this.attributeChangedCallback(mutation.attributeName, mutation.oldValue, super.getAttribute(mutation.attributeName));
}
}
}
Expand Down Expand Up @@ -1059,7 +1059,13 @@ var codeInput = {
}

if (mainTextarea.placeholder == oldValue || oldValue == null && mainTextarea.placeholder == "") {
mainTextarea.placeholder = newValue;
if(newValue === null) {
mainTextarea.removeAttribute("placeholder");
// If always setAttribute, would set it to the string
// "null" here, which isn't wanted.'
} else {
mainTextarea.setAttribute("placeholder", newValue);
}
}

this.scheduleHighlight();
Expand Down
19 changes: 19 additions & 0 deletions tests/tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,25 @@ console.log("I've got another line!", 2 &lt; 3, "should be true.");

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

if(!isHLJS) {
// These tests require autodetect plugin to be absent

codeInputElement.setAttribute("language", "css");
await waitAsync(50); // Wait for language to propogate to class
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"`);

window.requestAnimationFrame(function() {
codeInputElement.setAttribute("placeholder", "Gimme some HTML!");
codeInputElement.setAttribute("language", "html");
});
await waitAsync(500); // Wait for animation frame; language to propogate to class
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"`);

codeInputElement.removeAttribute("placeholder");
codeInputElement.setAttribute("language", "JavaScript");
await waitAsync(50); // Wait for language to propogate to class
}

/*--- Tests for plugins ---*/
// AutoCloseBrackets
testAddingText("AutoCloseBrackets", textarea, function(textarea) {
Expand Down