Skip to content

Commit

Permalink
Improve paste behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
hgiesel committed Jul 2, 2021
1 parent 7f4fd3d commit 19e1edf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
7 changes: 4 additions & 3 deletions ts/editor/TagEditor.svelte
Expand Up @@ -132,9 +132,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
activeInput.setSelectionRange(0, 0);
}
function insertTag(index: number): void {
if (!isActiveNameUniqueAt(index)) {
function insertTagKeepFocus(index: number): void {
if (isActiveNameUniqueAt(index)) {
tags.splice(index, 0, attachId(activeName));
active!++;
tags = tags;
}
}
Expand Down Expand Up @@ -418,7 +419,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
on:input={() => updateTagName(tag)}
on:tagsplit={({ detail }) =>
enterBehavior(index, detail.start, detail.end)}
on:tagadd={() => insertTag(index)}
on:tagadd={() => insertTagKeepFocus(index)}
on:tagdelete={() => deleteTagAt(index)}
on:tagjoinprevious={() => joinWithPreviousTag(index)}
on:tagjoinnext={() => joinWithNextTag(index)}
Expand Down
23 changes: 8 additions & 15 deletions ts/editor/TagInput.svelte
Expand Up @@ -139,8 +139,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
}
function onPaste(event: ClipboardEvent): void {
event.preventDefault();
if (!event.clipboardData) {
return;
}
Expand All @@ -153,21 +151,16 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
if (splitted.length === 0) {
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");
}
const last = splitted.pop()!;
name = last;
for (const pastedName of splitted.reverse()) {
name = pastedName;
dispatch("tagadd");
}
name = last;
}
onMount(() => input.focus());
Expand All @@ -187,7 +180,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
on:keydown
on:keyup
on:input
on:paste={onPaste}
on:paste|preventDefault={onPaste}
/>

<style lang="scss">
Expand Down

0 comments on commit 19e1edf

Please sign in to comment.