Fix some deletion behavior

This commit is contained in:
Henrik Giesel 2021-06-28 03:00:17 +02:00
parent ba64f50593
commit 39ffaf3427
2 changed files with 13 additions and 24 deletions

View file

@ -3,7 +3,7 @@ Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
-->
<script lang="typescript">
import { createEventDispatcher } from "svelte";
import { createEventDispatcher, onDestroy } from "svelte";
import type Dropdown from "bootstrap/js/dist/dropdown";
@ -27,10 +27,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
const dispatch = createEventDispatcher();
function select(index: number) {
selected = index;
}
const updateAutocomplete =
(createDropdown: (element: HTMLElement) => Dropdown) =>
(event: KeyboardEvent): Dropdown => {
@ -77,22 +73,17 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
return autocomplete;
};
function destroyAutocomplete(): void {
onDestroy(() => {
if (!autocomplete) {
return;
}
autocomplete.hide();
selected = null;
active = false;
}
});
</script>
<WithDropdownMenu let:menuId let:createDropdown>
<slot
updateAutocomplete={updateAutocomplete(createDropdown)}
{destroyAutocomplete}
/>
<slot updateAutocomplete={updateAutocomplete(createDropdown)} />
<DropdownMenu id={menuId} class={className}>
{#each displayed as tag, i}

View file

@ -110,8 +110,14 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
activeName = current;
appendTagAndFocusAt(index, splitOff);
active = null;
await tick();
if (index === active) {
// splitOff tag was rejected
return;
}
input.setSelectionRange(0, 0);
}
@ -127,8 +133,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
tags = tags;
console.log("dt", activeAfterBlur, index);
if (active !== null && active > index) {
active--;
if (activeAfterBlur !== null && activeAfterBlur > index) {
activeAfterBlur--;
}
return deleted;
@ -138,6 +144,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
const deleted = tags.splice(index, 1)[0];
tags = tags;
console.log("dta", active, activeAfterBlur, index, JSON.stringify(tags));
if (activeAfterBlur === index) {
activeAfterBlur = null;
} else if (activeAfterBlur !== null && activeAfterBlur > index) {
@ -227,7 +234,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
search={tags[active ?? -1]?.name ?? ""}
on:autocomplete={onAutocomplete}
let:updateAutocomplete
let:destroyAutocomplete
>
<TagInput
id={tag.id}
@ -247,7 +253,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
on:tagaccept={() => {
console.log("accept", tag, index, activeName);
deleteActiveTagIfNotUnique(tag, index);
destroyAutocomplete();
decideNextActive();
tag.name = activeName;
}}
@ -267,13 +272,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
class="tag-spacer flex-grow-1 align-self-stretch"
on:click={appendEmptyTag}
/>
<div>
a, aab, an, ac: {active}
{activeAfterBlur} "{activeName}";
<br />
{JSON.stringify(tags)}
</div>
</ButtonToolbar>
</div>
</StickyBottom>