mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
Fix double delete on empty input
This commit is contained in:
parent
2de2f03db8
commit
bde820569a
3 changed files with 16 additions and 13 deletions
|
@ -30,15 +30,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
event.stopPropagation();
|
||||
}
|
||||
|
||||
function updateTag(event: Event) {
|
||||
function deactivate() {
|
||||
active = false;
|
||||
|
||||
if (name.length === 0) {
|
||||
deleteTag(event);
|
||||
} else {
|
||||
dispatch("tagupdate");
|
||||
event.stopPropagation();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
@ -47,10 +40,13 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
bind:name
|
||||
bind:input
|
||||
on:focus
|
||||
on:blur={() => (active = false)}
|
||||
on:blur={deactivate}
|
||||
on:blur
|
||||
on:keydown
|
||||
on:tagupdate={updateTag}
|
||||
on:tagupdate={deactivate}
|
||||
on:tagupdate
|
||||
on:tagdelete={deactivate}
|
||||
on:tagdelete
|
||||
on:tagadd
|
||||
on:tagjoinprevious
|
||||
on:tagjoinnext
|
||||
|
|
|
@ -68,6 +68,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
}
|
||||
|
||||
function deleteTagAt(index: number): void {
|
||||
console.log("eyo", index);
|
||||
tags.splice(index, 1);
|
||||
tags = tags;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,12 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
|
||||
function onAccept(): void {
|
||||
name = normalizeTagname(name);
|
||||
dispatch("tagupdate", { name });
|
||||
if (name.length > 0) {
|
||||
dispatch("tagupdate");
|
||||
} else {
|
||||
console.log("dispatch delete in taginput", name);
|
||||
dispatch("tagdelete");
|
||||
}
|
||||
}
|
||||
|
||||
async function onBackspace(event: KeyboardEvent): Promise<void> {
|
||||
|
@ -72,7 +77,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
} else if (event.code === "Delete") {
|
||||
onDelete(event);
|
||||
} else if (event.code === "Enter") {
|
||||
onAccept();
|
||||
/* should probably do something else */
|
||||
input.blur();
|
||||
event.preventDefault();
|
||||
}
|
||||
}
|
||||
|
@ -120,8 +126,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
tabindex="-1"
|
||||
size="1"
|
||||
on:focus
|
||||
on:blur
|
||||
on:blur={onAccept}
|
||||
on:blur
|
||||
on:keydown={onKeydown}
|
||||
on:keydown
|
||||
on:paste={onPaste}
|
||||
|
|
Loading…
Reference in a new issue