mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Improve paste behavior
This commit is contained in:
parent
cdc4fd0ef8
commit
5a988f72fa
2 changed files with 14 additions and 20 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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)}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
@ -153,22 +151,17 @@ 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) {
|
||||
for (const pastedName of splitted.reverse()) {
|
||||
name = pastedName;
|
||||
dispatch("tagadd");
|
||||
}
|
||||
|
||||
name = last;
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => input.focus());
|
||||
</script>
|
||||
|
@ -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">
|
||||
|
|
Loading…
Reference in a new issue