Skip to content

Commit 2b75829

Browse files
committed
Clean up autocomplete demo and make code-input retain focus so autocomplete works
1 parent 88408f7 commit 2b75829

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

docs/plugins/_index.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ Right now, you can only add one plugin of each type (e.g. one SelectTokenCallbac
9595
let autocompleteButton = document.createElement("button");
9696
autocompleteButton.innerHTML = "<i>" + tag.substring(0, start_tag.length) + "</i>" + tag.substring(start_tag.length, tag.length);
9797
autocompleteButton.addEventListener("click", () => {
98+
textarea.parentElement.focus();
9899
document.execCommand("insertText", false, tag.substring(start_tag.length, tag.length));
99100
popupElem.innerHTML = ""; // On popup
100101
});
@@ -103,18 +104,18 @@ Right now, you can only add one plugin of each type (e.g. one SelectTokenCallbac
103104
});
104105
105106
if(popupElem.firstElementChild != null) {
106-
popupElem.firstElementChild.innerHTML += "[Tab]";
107+
popupElem.firstElementChild.innerHTML += "[Tab]";
107108
}
108109
textarea.addEventListener("keydown", (event) => {
109-
if(event.key == "Tab" && popupElem.firstElementChild != null) {
110-
popupElem.firstElementChild.click();
111-
event.preventDefault();
112-
}
110+
if(event.key == "Tab" && popupElem.firstElementChild != null) {
111+
popupElem.firstElementChild.click();
112+
event.preventDefault();
113+
}
113114
})
114115
}
115116
// Pass at register
116117
codeInput.registerTemplate("syntax-highlighted", new codeInput.templates.Prism(Prism, [
117-
new codeInput.plugins.Autocomplete(updatePopup) // See above
118+
new codeInput.plugins.Autocomplete(updatePopup) // See above
118119
]));
119120
</script>
120121
<p>Start typing some HTML tags to see the autocomplete in action. You can click an autocomplete suggestion, or press the Tab key to select the first.</p>

0 commit comments

Comments
 (0)