Invert if

This commit is contained in:
Jan Bader 2022-03-02 19:49:22 +00:00
parent 6fcd555493
commit e708cd5d0e

View File

@ -44,22 +44,25 @@ function load(text: String) {
}); });
}; };
function keypress(e: KeyboardEvent) { function keypress(e: KeyboardEvent) {
if (e.key == "Enter") { if (e.key != "Enter")
const selected = Suggestions.value[0]; return;
selectElement(selected);
const el = (<HTMLInputElement>e.target); const selected = Suggestions.value[0];
const inputElements = Array.from(el.ownerDocument.querySelectorAll('input:not([disabled]):not([readonly])')); selectElement(selected);
const currentIndex = inputElements.indexOf(el); const el = (<HTMLInputElement>e.target);
const nextElement = inputElements[currentIndex < inputElements.length - 1 ? currentIndex + 1 : 0]; const inputElements = Array.from(el.ownerDocument.querySelectorAll('input:not([disabled]):not([readonly])'));
(<HTMLInputElement>nextElement).focus(); const currentIndex = inputElements.indexOf(el);
} const nextElement = inputElements[currentIndex < inputElements.length - 1 ? currentIndex + 1 : 0];
(<HTMLInputElement>nextElement).focus();
}; };
function selectElement(element: Suggestion) { function selectElement(element: Suggestion) {
emit('update:id', element.ID); emit('update:id', element.ID);
emit('update:text', element.Name); emit('update:text', element.Name);
emit('update:type', element.Type); emit('update:type', element.Type);
Suggestions.value = []; Suggestions.value = [];
}; };
function select(e: MouseEvent) { function select(e: MouseEvent) {
const target = (<HTMLInputElement>e.target); const target = (<HTMLInputElement>e.target);
const valueAttribute = target.attributes.getNamedItem("value"); const valueAttribute = target.attributes.getNamedItem("value");
@ -69,6 +72,7 @@ function select(e: MouseEvent) {
const selected = Suggestions.value.filter(x => x.ID == selectedID)[0]; const selected = Suggestions.value.filter(x => x.ID == selectedID)[0];
selectElement(selected); selectElement(selected);
}; };
function clear() { function clear() {
emit('update:id', null); emit('update:id', null);
emit('update:text', SearchQuery.value); emit('update:text', SearchQuery.value);