Improve paste behavior

This commit is contained in:
Henrik Giesel 2021-07-02 13:47:36 +02:00
parent cdc4fd0ef8
commit 5a988f72fa
2 changed files with 14 additions and 20 deletions

View file

@ -132,9 +132,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
activeInput.setSelectionRange(0, 0); activeInput.setSelectionRange(0, 0);
} }
function insertTag(index: number): void { function insertTagKeepFocus(index: number): void {
if (!isActiveNameUniqueAt(index)) { if (isActiveNameUniqueAt(index)) {
tags.splice(index, 0, attachId(activeName)); tags.splice(index, 0, attachId(activeName));
active!++;
tags = tags; tags = tags;
} }
} }
@ -418,7 +419,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
on:input={() => updateTagName(tag)} on:input={() => updateTagName(tag)}
on:tagsplit={({ detail }) => on:tagsplit={({ detail }) =>
enterBehavior(index, detail.start, detail.end)} enterBehavior(index, detail.start, detail.end)}
on:tagadd={() => insertTag(index)} on:tagadd={() => insertTagKeepFocus(index)}
on:tagdelete={() => deleteTagAt(index)} on:tagdelete={() => deleteTagAt(index)}
on:tagjoinprevious={() => joinWithPreviousTag(index)} on:tagjoinprevious={() => joinWithPreviousTag(index)}
on:tagjoinnext={() => joinWithNextTag(index)} on:tagjoinnext={() => joinWithNextTag(index)}

View file

@ -139,8 +139,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
} }
function onPaste(event: ClipboardEvent): void { function onPaste(event: ClipboardEvent): void {
event.preventDefault();
if (!event.clipboardData) { if (!event.clipboardData) {
return; return;
} }
@ -153,21 +151,16 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
if (splitted.length === 0) { if (splitted.length === 0) {
return; return;
} else if (splitted.length === 1) {
name = splitted.shift()!;
} else {
name = splitted.shift()!;
dispatch("tagadd");
const last = splitted.pop()!;
for (const pastedName of splitted) {
name = pastedName;
dispatch("tagadd");
}
name = last;
} }
const last = splitted.pop()!;
for (const pastedName of splitted.reverse()) {
name = pastedName;
dispatch("tagadd");
}
name = last;
} }
onMount(() => input.focus()); onMount(() => input.focus());
@ -187,7 +180,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
on:keydown on:keydown
on:keyup on:keyup
on:input on:input
on:paste={onPaste} on:paste|preventDefault={onPaste}
/> />
<style lang="scss"> <style lang="scss">