diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.ts index 12a30f08a..305d8306a 100644 --- a/app/src/protyle/toolbar/index.ts +++ b/app/src/protyle/toolbar/index.ts @@ -1252,16 +1252,17 @@ export class Toolbar { } }); inputElement.addEventListener("input", (event) => { - const mathLanguages: string[] = []; + const matchLanguages: string[] = []; Constants.CODE_LANGUAGES.forEach((item) => { if (item.indexOf(inputElement.value.toLowerCase()) > -1) { - mathLanguages.push(item); + matchLanguages.push(item); } }); let html = ""; // sort - mathLanguages.sort((a, b) => { + let matchInput = false; + matchLanguages.sort((a, b) => { if (a.startsWith(inputElement.value.toLowerCase()) && b.startsWith(inputElement.value.toLowerCase())) { if (a.length < b.length) { return -1; @@ -1278,8 +1279,14 @@ export class Toolbar { return 0; } }).forEach((item) => { + if (inputElement.value === item) { + matchInput = true + } html += `
${item.replace(inputElement.value.toLowerCase(), "" + inputElement.value.toLowerCase() + "")}
`; }); + if (inputElement.value.trim() && !matchInput) { + html = `
${inputElement.value.replace(/`| /g, "_")}
${html}`; + } this.subElement.firstElementChild.lastElementChild.innerHTML = html; if (html) { this.subElement.firstElementChild.lastElementChild.firstElementChild.classList.add("b3-list-item--focus");