mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00
Reimplement tagjoin with tick()
This commit is contained in:
parent
180ef140f8
commit
fe35573308
2 changed files with 18 additions and 28 deletions
|
@ -56,36 +56,24 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
tags = tags;
|
tags = tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
function joinWithPreviousTag(
|
function joinWithPreviousTag(index: number): void {
|
||||||
index: number,
|
|
||||||
setPosition: (position: number) => void
|
|
||||||
): void {
|
|
||||||
if (index === 0) {
|
if (index === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const spliced = tags.splice(index - 1, 1)[0];
|
const spliced = tags.splice(index - 1, 1)[0];
|
||||||
const length = spliced.name.length;
|
|
||||||
tags[index - 1].name = spliced.name + tags[index - 1].name;
|
tags[index - 1].name = spliced.name + tags[index - 1].name;
|
||||||
tags = tags;
|
tags = tags;
|
||||||
|
|
||||||
setPosition(length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function joinWithNextTag(
|
function joinWithNextTag(index: number): void {
|
||||||
index: number,
|
|
||||||
setPosition: (position: number) => void
|
|
||||||
): void {
|
|
||||||
if (index === tags.length - 1) {
|
if (index === tags.length - 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const spliced = tags.splice(index + 1, 1)[0];
|
const spliced = tags.splice(index + 1, 1)[0];
|
||||||
const length = tags[index].name.length;
|
|
||||||
tags[index].name = tags[index].name + spliced.name;
|
tags[index].name = tags[index].name + spliced.name;
|
||||||
tags = tags;
|
tags = tags;
|
||||||
|
|
||||||
setPosition(length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function moveToPreviousTag(index: number): void {
|
function moveToPreviousTag(index: number): void {
|
||||||
|
@ -115,13 +103,12 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
newName = "";
|
newName = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
function joinWithLastTag(setPosition: (position: number) => void): void {
|
function joinWithLastTag(): void {
|
||||||
const popped = tags.pop();
|
const popped = tags.pop();
|
||||||
tags = tags;
|
tags = tags;
|
||||||
|
|
||||||
if (popped) {
|
if (popped) {
|
||||||
newName = popped.name + newName;
|
newName = popped.name + newName;
|
||||||
setPosition(popped.name.length);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,10 +136,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
on:tagupdate={() => checkForDuplicateAt(index)}
|
on:tagupdate={() => checkForDuplicateAt(index)}
|
||||||
on:tagadd={() => insertTagAt(index)}
|
on:tagadd={() => insertTagAt(index)}
|
||||||
on:tagdelete={() => deleteTagAt(index)}
|
on:tagdelete={() => deleteTagAt(index)}
|
||||||
on:tagjoinprevious={({ detail }) =>
|
on:tagjoinprevious={() => joinWithPreviousTag(index)}
|
||||||
joinWithPreviousTag(index, detail.setPosition)}
|
on:tagjoinnext={() => joinWithNextTag(index)}
|
||||||
on:tagjoinnext={({ detail }) =>
|
|
||||||
joinWithNextTag(index, detail.setPosition)}
|
|
||||||
on:tagmoveprevious={() => moveToPreviousTag(index)}
|
on:tagmoveprevious={() => moveToPreviousTag(index)}
|
||||||
on:tagmovenext={() => moveToNextTag(index)}
|
on:tagmovenext={() => moveToNextTag(index)}
|
||||||
/>
|
/>
|
||||||
|
@ -165,8 +150,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
on:blur={destroyAutocomplete}
|
on:blur={destroyAutocomplete}
|
||||||
on:tagupdate={appendTag}
|
on:tagupdate={appendTag}
|
||||||
on:tagadd={appendTag}
|
on:tagadd={appendTag}
|
||||||
on:tagjoinprevious={({ detail }) =>
|
on:tagjoinprevious={joinWithLastTag}
|
||||||
joinWithLastTag(detail.setPosition)}
|
|
||||||
on:tagmoveprevious={moveToLastTag}
|
on:tagmoveprevious={moveToLastTag}
|
||||||
/>
|
/>
|
||||||
</TagAutocomplete>
|
</TagAutocomplete>
|
||||||
|
|
|
@ -3,7 +3,7 @@ Copyright: Ankitects Pty Ltd and contributors
|
||||||
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
-->
|
-->
|
||||||
<script lang="typescript">
|
<script lang="typescript">
|
||||||
import { createEventDispatcher, onMount } from "svelte";
|
import { createEventDispatcher, onMount, tick } from "svelte";
|
||||||
import { normalizeTagname } from "./tags";
|
import { normalizeTagname } from "./tags";
|
||||||
|
|
||||||
export let name: string;
|
export let name: string;
|
||||||
|
@ -23,7 +23,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
}
|
}
|
||||||
|
|
||||||
function setPosition(position: number): void {
|
function setPosition(position: number): void {
|
||||||
setTimeout(() => input.setSelectionRange(position, position));
|
input.setSelectionRange(position, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onAccept(): void {
|
function onAccept(): void {
|
||||||
|
@ -31,9 +31,12 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
dispatch("tagupdate", { name });
|
dispatch("tagupdate", { name });
|
||||||
}
|
}
|
||||||
|
|
||||||
function onBackspace(event: KeyboardEvent) {
|
async function onBackspace(event: KeyboardEvent): Promise<void> {
|
||||||
if (caretAtStart()) {
|
if (caretAtStart()) {
|
||||||
dispatch("tagjoinprevious", { setPosition });
|
const length = input.value.length;
|
||||||
|
dispatch("tagjoinprevious");
|
||||||
|
await tick();
|
||||||
|
setPosition(input.value.length - length);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
} else if (name.endsWith("::")) {
|
} else if (name.endsWith("::")) {
|
||||||
name = name.slice(0, -2);
|
name = name.slice(0, -2);
|
||||||
|
@ -41,9 +44,12 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onDelete(event: KeyboardEvent) {
|
async function onDelete(event: KeyboardEvent): Promise<void> {
|
||||||
if (caretAtEnd()) {
|
if (caretAtEnd()) {
|
||||||
dispatch("tagjoinnext", { setPosition });
|
const length = input.value.length;
|
||||||
|
dispatch("tagjoinnext");
|
||||||
|
await tick();
|
||||||
|
setPosition(length);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
} else if (name.endsWith("::")) {
|
} else if (name.endsWith("::")) {
|
||||||
name = name.slice(0, -2);
|
name = name.slice(0, -2);
|
||||||
|
|
Loading…
Reference in a new issue