Remove deleteActiveTag, fix appendEmptyTag

This commit is contained in:
Henrik Giesel 2021-06-28 03:18:50 +02:00
parent 39ffaf3427
commit a034c93eb7

View file

@ -46,10 +46,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
} }
} }
function updateTagName() { function updateWithTagName(tag: TagType): void {
console.log("updatetagname"); tag.name = activeName;
const activeTag = tags[active!];
activeTag.name = activeName;
tags = tags; tags = tags;
} }
@ -64,13 +62,11 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
const lastTag = tags[tags.length - 1]; const lastTag = tags[tags.length - 1];
if (!lastTag || lastTag.name.length > 0) { if (!lastTag || lastTag.name.length > 0) {
tags.splice(tags.length, 0, attachId("")); appendTagAndFocusAt(tags.length - 1, "");
tags = tags;
} }
const tagsHadFocus = active === null; const tagsHadFocus = active === null;
active = null; active = null;
setActiveAfterBlur(tags.length - 1);
if (tagsHadFocus) { if (tagsHadFocus) {
decideNextActive(); decideNextActive();
@ -128,7 +124,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
} }
} }
function deleteTag(index: number): TagType { function deleteTagAt(index: number): TagType {
const deleted = tags.splice(index, 1)[0]; const deleted = tags.splice(index, 1)[0];
tags = tags; tags = tags;
@ -140,28 +136,14 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
return deleted; return deleted;
} }
function deleteActiveTag(tag: TagType, index: number): TagType {
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) {
activeAfterBlur--;
}
active = null;
return deleted;
}
function joinWithPreviousTag(index: number): void { function joinWithPreviousTag(index: number): void {
if (isFirst(index)) { if (isFirst(index)) {
return; return;
} }
const deleted = deleteTag(index - 1); const deleted = deleteTagAt(index - 1);
activeName = deleted.name + activeName; activeName = deleted.name + activeName;
active = active! - 1;
console.log("joinprevious", activeName, active); console.log("joinprevious", activeName, active);
tags = tags; tags = tags;
} }
@ -171,7 +153,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
return; return;
} }
const deleted = deleteTag(index + 1); const deleted = deleteTagAt(index + 1);
activeName = activeName + deleted.name; activeName = activeName + deleted.name;
tags = tags; tags = tags;
} }
@ -203,14 +185,14 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
input.setSelectionRange(0, 0); input.setSelectionRange(0, 0);
} }
function deleteActiveTagIfNotUnique(tag: TagType, index: number): void { function deleteTagIfNotUnique(tag: TagType, index: number): void {
if (!tags.includes(tag)) { if (!tags.includes(tag)) {
// already deleted // already deleted
return; return;
} }
if (!isActiveNameUniqueAt(index)) { if (!isActiveNameUniqueAt(index)) {
deleteActiveTag(tag, index); deleteTagAt(index);
} }
} }
@ -241,20 +223,22 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
bind:input bind:input
on:focus={() => (activeName = tag.name)} on:focus={() => (activeName = tag.name)}
on:keydown={updateAutocomplete} on:keydown={updateAutocomplete}
on:input={updateTagName} on:input={() => updateWithTagName(tag)}
on:tagsplit={({ detail }) => on:tagsplit={({ detail }) =>
splitTag(index, detail.start, detail.end)} splitTag(index, detail.start, detail.end)}
on:tagadd={() => insertTag(index)} on:tagadd={() => insertTag(index)}
on:tagdelete={() => deleteActiveTag(tag, index)} on:tagdelete={() => deleteTagAt(index)}
on:tagjoinprevious={() => joinWithPreviousTag(index)} on:tagjoinprevious={() => joinWithPreviousTag(index)}
on:tagjoinnext={() => joinWithNextTag(index)} on:tagjoinnext={() => joinWithNextTag(index)}
on:tagmoveprevious={() => moveToPreviousTag(index)} on:tagmoveprevious={() => moveToPreviousTag(index)}
on:tagmovenext={() => moveToNextTag(index)} on:tagmovenext={() => moveToNextTag(index)}
on:tagaccept={() => { on:tagaccept={() => {
console.log("accept", tag, index, activeName); console.log("accept", tag, index, activeName);
deleteActiveTagIfNotUnique(tag, index); deleteTagIfNotUnique(tag, index);
decideNextActive(); decideNextActive();
tag.name = activeName; if (tag) {
updateWithTagName(tag);
}
}} }}
/> />
</TagAutocomplete> </TagAutocomplete>
@ -263,7 +247,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
name={tag.name} name={tag.name}
bind:blink={tag.blink} bind:blink={tag.blink}
on:click={() => (active = index)} on:click={() => (active = index)}
on:tagdelete={() => deleteTag(index)} on:tagdelete={() => deleteTagAt(index)}
/> />
{/if} {/if}
{/each} {/each}
@ -272,6 +256,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
class="tag-spacer flex-grow-1 align-self-stretch" class="tag-spacer flex-grow-1 align-self-stretch"
on:click={appendEmptyTag} on:click={appendEmptyTag}
/> />
{active}
{activeAfterBlur}
</ButtonToolbar> </ButtonToolbar>
</div> </div>
</StickyBottom> </StickyBottom>