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();
|
event.stopPropagation();
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateTag(event: Event) {
|
function deactivate() {
|
||||||
active = false;
|
active = false;
|
||||||
|
|
||||||
if (name.length === 0) {
|
|
||||||
deleteTag(event);
|
|
||||||
} else {
|
|
||||||
dispatch("tagupdate");
|
|
||||||
event.stopPropagation();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -47,10 +40,13 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
bind:name
|
bind:name
|
||||||
bind:input
|
bind:input
|
||||||
on:focus
|
on:focus
|
||||||
on:blur={() => (active = false)}
|
on:blur={deactivate}
|
||||||
on:blur
|
on:blur
|
||||||
on:keydown
|
on:keydown
|
||||||
on:tagupdate={updateTag}
|
on:tagupdate={deactivate}
|
||||||
|
on:tagupdate
|
||||||
|
on:tagdelete={deactivate}
|
||||||
|
on:tagdelete
|
||||||
on:tagadd
|
on:tagadd
|
||||||
on:tagjoinprevious
|
on:tagjoinprevious
|
||||||
on:tagjoinnext
|
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 {
|
function deleteTagAt(index: number): void {
|
||||||
|
console.log("eyo", index);
|
||||||
tags.splice(index, 1);
|
tags.splice(index, 1);
|
||||||
tags = tags;
|
tags = tags;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,12 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
function onAccept(): void {
|
function onAccept(): void {
|
||||||
name = normalizeTagname(name);
|
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> {
|
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") {
|
} else if (event.code === "Delete") {
|
||||||
onDelete(event);
|
onDelete(event);
|
||||||
} else if (event.code === "Enter") {
|
} else if (event.code === "Enter") {
|
||||||
onAccept();
|
/* should probably do something else */
|
||||||
|
input.blur();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,8 +126,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
size="1"
|
size="1"
|
||||||
on:focus
|
on:focus
|
||||||
on:blur
|
|
||||||
on:blur={onAccept}
|
on:blur={onAccept}
|
||||||
|
on:blur
|
||||||
on:keydown={onKeydown}
|
on:keydown={onKeydown}
|
||||||
on:keydown
|
on:keydown
|
||||||
on:paste={onPaste}
|
on:paste={onPaste}
|
||||||
|
|
Loading…
Reference in a new issue