mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04:00
Fix behavior when autocompletion shows
This commit is contained in:
parent
54c1f54ab0
commit
392326b863
1 changed files with 18 additions and 16 deletions
|
@ -230,27 +230,31 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
activeAfterBlur = null;
|
||||
}
|
||||
|
||||
function printableKey(event: KeyboardEvent): boolean {
|
||||
return (
|
||||
(event.location === KeyboardEvent.DOM_KEY_LOCATION_STANDARD ||
|
||||
event.location === KeyboardEvent.DOM_KEY_LOCATION_NUMPAD) &&
|
||||
!event.code.startsWith("Arrow") &&
|
||||
event.code !== "Backspace" && event.code !== "Delete"
|
||||
);
|
||||
function isPrintableKey(event: KeyboardEvent): boolean {
|
||||
return event.key.length === 1;
|
||||
}
|
||||
|
||||
function isDeletionKey(event: KeyboardEvent): boolean {
|
||||
return event.code === "Backspace" || event.code === "Delete";
|
||||
}
|
||||
|
||||
function update(event: KeyboardEvent, autocomplete: any): void {
|
||||
const visible = autocomplete.isVisible();
|
||||
const printable = printableKey(event);
|
||||
const printable = isPrintableKey(event);
|
||||
const deletion = isDeletionKey(event);
|
||||
|
||||
if (!visible) {
|
||||
if (printable) {
|
||||
if (printable || deletion) {
|
||||
autocomplete.show();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (activeName.length === 0) {
|
||||
autocomplete.hide();
|
||||
}
|
||||
|
||||
switch (event.code) {
|
||||
case "ArrowUp":
|
||||
autocomplete.selectNext();
|
||||
|
@ -264,25 +268,23 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
|
||||
case "Tab":
|
||||
if (event.shiftKey) {
|
||||
autocomplete.selectNext();
|
||||
} else {
|
||||
autocomplete.selectPrevious();
|
||||
} else {
|
||||
autocomplete.selectNext();
|
||||
}
|
||||
event.preventDefault();
|
||||
break;
|
||||
|
||||
case "Enter":
|
||||
console.log("choose");
|
||||
autocomplete.chooseSelected();
|
||||
event.preventDefault();
|
||||
break;
|
||||
|
||||
default:
|
||||
if (!printable) {
|
||||
return;
|
||||
if (printable || deletion) {
|
||||
autocomplete.update();
|
||||
}
|
||||
|
||||
autocomplete.update();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -298,7 +300,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
<div class="pb-1">
|
||||
{#if index === active}
|
||||
<WithAutocomplete
|
||||
class="d-flex flex-column-reverse"
|
||||
class="d-flex flex-column-reverse dropup"
|
||||
{suggestionsPromise}
|
||||
on:update={updateSuggestions}
|
||||
on:autocomplete={({ detail }) =>
|
||||
|
|
Loading…
Reference in a new issue