mirror of
https://github.com/ankitects/anki.git
synced 2025-09-23 00:12:25 -04:00
Add .input to Tag interface
This commit is contained in:
parent
e68f874c80
commit
ea1e5b5840
3 changed files with 18 additions and 21 deletions
|
@ -9,13 +9,12 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
import { deleteIcon } from "./icons";
|
import { deleteIcon } from "./icons";
|
||||||
|
|
||||||
export let name: string;
|
export let name: string;
|
||||||
|
export let input: HTMLInputElement;
|
||||||
export let active: boolean;
|
export let active: boolean;
|
||||||
export let blink: boolean = false;
|
export let blink: boolean = false;
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
let input: HTMLInputElement;
|
|
||||||
|
|
||||||
$: if (blink) {
|
$: if (blink) {
|
||||||
setTimeout(() => (blink = false), 300);
|
setTimeout(() => (blink = false), 300);
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,18 +69,13 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function insertTagAt(index: number): boolean {
|
function insertTagAt(index: number): void {
|
||||||
const names = tags.map(getName);
|
const name = tags.map(getName).splice(index, 1)[0];
|
||||||
const newName = names.splice(index, 1)[0];
|
|
||||||
let added = false;
|
|
||||||
|
|
||||||
if (!checkIfContainsNameAt(index) && newName.length > 0) {
|
|
||||||
tags.splice(index, 0, attachId(newName));
|
|
||||||
added = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (!checkIfContainsNameAt(index)) {
|
||||||
|
tags.splice(index, 0, attachId(name));
|
||||||
tags = tags;
|
tags = tags;
|
||||||
return added;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteTagAt(index: number): void {
|
function deleteTagAt(index: number): void {
|
||||||
|
@ -89,7 +84,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
}
|
}
|
||||||
|
|
||||||
function joinWithPreviousTag(index: number): void {
|
function joinWithPreviousTag(index: number): void {
|
||||||
if (index === 0) {
|
if (isFirst(index)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +94,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
}
|
}
|
||||||
|
|
||||||
function joinWithNextTag(index: number): void {
|
function joinWithNextTag(index: number): void {
|
||||||
if (index === tags.length - 1) {
|
if (isLast(index)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,12 +104,12 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
}
|
}
|
||||||
|
|
||||||
function moveToPreviousTag(index: number): void {
|
function moveToPreviousTag(index: number): void {
|
||||||
if (index === 0 || tags.length === 1) {
|
if (isFirst(index)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tags[index - 1].active = true;
|
const previousTag = tags[index - 1];
|
||||||
tags[index].active = false;
|
previousTag.active = true;
|
||||||
tags = tags;
|
tags = tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,11 +119,12 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tags[index + 1].active = true;
|
const nextTag = tags[index + 1];
|
||||||
|
nextTag.active = true;
|
||||||
tags = tags;
|
tags = tags;
|
||||||
|
|
||||||
await tick();
|
await tick();
|
||||||
(document.activeElement as HTMLInputElement).setSelectionRange(0, 0);
|
nextTag.input?.setSelectionRange(0, 0);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -146,6 +142,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
{#each tags as tag, index (tag.id)}
|
{#each tags as tag, index (tag.id)}
|
||||||
<Tag
|
<Tag
|
||||||
bind:name={tag.name}
|
bind:name={tag.name}
|
||||||
|
bind:input={tag.input}
|
||||||
bind:active={tag.active}
|
bind:active={tag.active}
|
||||||
bind:blink={tag.blink}
|
bind:blink={tag.blink}
|
||||||
on:tagupdate={() => addTagAt(index)}
|
on:tagupdate={() => addTagAt(index)}
|
||||||
|
|
|
@ -16,18 +16,19 @@ export function normalizeTagname(tagname: string): string {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Tag {
|
interface Tag {
|
||||||
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
input?: HTMLInputElement;
|
||||||
active: boolean;
|
active: boolean;
|
||||||
blink: boolean;
|
blink: boolean;
|
||||||
id: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function attachId(name: string, active = false): Tag {
|
export function attachId(name: string, active = false): Tag {
|
||||||
return {
|
return {
|
||||||
|
id: Math.random().toString(36).substring(2),
|
||||||
name,
|
name,
|
||||||
active,
|
active,
|
||||||
blink: false,
|
blink: false,
|
||||||
id: Math.random().toString(36).substring(2),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue