mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
tagmove should act like tagjoin on empty inputs
This commit is contained in:
parent
bde820569a
commit
796c759333
2 changed files with 57 additions and 24 deletions
|
@ -128,6 +128,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
tags = tags;
|
tags = tags;
|
||||||
newName = "";
|
newName = "";
|
||||||
|
|
||||||
return added;
|
return added;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,7 +141,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function moveToLastTag(): void {
|
async function moveToLastTag(): Promise<void> {
|
||||||
const newTag = appendTag() ? tags[tags.length - 2] : tags[tags.length - 1];
|
const newTag = appendTag() ? tags[tags.length - 2] : tags[tags.length - 1];
|
||||||
newTag.active = true;
|
newTag.active = true;
|
||||||
}
|
}
|
||||||
|
@ -183,6 +184,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
on:tagadd={appendTag}
|
on:tagadd={appendTag}
|
||||||
on:tagjoinprevious={joinWithLastTag}
|
on:tagjoinprevious={joinWithLastTag}
|
||||||
on:tagmoveprevious={moveToLastTag}
|
on:tagmoveprevious={moveToLastTag}
|
||||||
|
on:tagmovenext={appendTag}
|
||||||
/>
|
/>
|
||||||
</TagAutocomplete>
|
</TagAutocomplete>
|
||||||
</ButtonToolbar>
|
</ButtonToolbar>
|
||||||
|
|
|
@ -26,36 +26,58 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
input.setSelectionRange(position, position);
|
input.setSelectionRange(position, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onAccept(): void {
|
function isEmpty(): boolean {
|
||||||
|
return name.length === 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalize(): void {
|
||||||
name = normalizeTagname(name);
|
name = normalizeTagname(name);
|
||||||
if (name.length > 0) {
|
}
|
||||||
dispatch("tagupdate");
|
|
||||||
} else {
|
function onAccept(): void {
|
||||||
console.log("dispatch delete in taginput", name);
|
normalize();
|
||||||
dispatch("tagdelete");
|
dispatch(name.length > 0 ? "tagupdate" : "tagdelete");
|
||||||
|
}
|
||||||
|
|
||||||
|
let acceptByEnter = true;
|
||||||
|
|
||||||
|
function onBlur(): void {
|
||||||
|
// do not cause double accept if accept causes blur
|
||||||
|
if (!acceptByEnter) {
|
||||||
|
onAccept();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
acceptByEnter = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function joinWithPreviousTag(event: Event): Promise<void> {
|
||||||
|
const length = input.value.length;
|
||||||
|
dispatch("tagjoinprevious");
|
||||||
|
await tick();
|
||||||
|
setPosition(input.value.length - length);
|
||||||
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onBackspace(event: KeyboardEvent): Promise<void> {
|
async function onBackspace(event: KeyboardEvent): Promise<void> {
|
||||||
if (caretAtStart()) {
|
if (caretAtStart()) {
|
||||||
const length = input.value.length;
|
joinWithPreviousTag(event);
|
||||||
dispatch("tagjoinprevious");
|
|
||||||
await tick();
|
|
||||||
setPosition(input.value.length - length);
|
|
||||||
event.preventDefault();
|
|
||||||
} else if (name.endsWith("::")) {
|
} else if (name.endsWith("::")) {
|
||||||
name = name.slice(0, -2);
|
name = name.slice(0, -2);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function joinWithNextTag(event: Event): Promise<void> {
|
||||||
|
const length = input.value.length;
|
||||||
|
dispatch("tagjoinnext");
|
||||||
|
await tick();
|
||||||
|
setPosition(length);
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
async function onDelete(event: KeyboardEvent): Promise<void> {
|
async function onDelete(event: KeyboardEvent): Promise<void> {
|
||||||
if (caretAtEnd()) {
|
if (caretAtEnd()) {
|
||||||
const length = input.value.length;
|
joinWithNextTag(event);
|
||||||
dispatch("tagjoinnext");
|
|
||||||
await tick();
|
|
||||||
setPosition(length);
|
|
||||||
event.preventDefault();
|
|
||||||
} else if (name.endsWith("::")) {
|
} else if (name.endsWith("::")) {
|
||||||
name = name.slice(0, -2);
|
name = name.slice(0, -2);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
@ -67,18 +89,27 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
name += "::";
|
name += "::";
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
} else if (event.code === "ArrowLeft" && caretAtStart()) {
|
} else if (event.code === "ArrowLeft" && caretAtStart()) {
|
||||||
dispatch("tagmoveprevious");
|
normalize();
|
||||||
event.preventDefault();
|
if (isEmpty()) {
|
||||||
|
joinWithPreviousTag(event);
|
||||||
|
} else {
|
||||||
|
dispatch("tagmoveprevious");
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
} else if (event.code === "ArrowRight" && caretAtEnd()) {
|
} else if (event.code === "ArrowRight" && caretAtEnd()) {
|
||||||
dispatch("tagmovenext");
|
if (isEmpty()) {
|
||||||
event.preventDefault();
|
joinWithNextTag(event);
|
||||||
|
} else {
|
||||||
|
dispatch("tagmovenext");
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
} else if (event.code === "Backspace") {
|
} else if (event.code === "Backspace") {
|
||||||
onBackspace(event);
|
onBackspace(event);
|
||||||
} else if (event.code === "Delete") {
|
} else if (event.code === "Delete") {
|
||||||
onDelete(event);
|
onDelete(event);
|
||||||
} else if (event.code === "Enter") {
|
} else if (event.code === "Enter") {
|
||||||
/* should probably do something else */
|
onAccept();
|
||||||
input.blur();
|
acceptByEnter = true;
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,7 +157,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
size="1"
|
size="1"
|
||||||
on:focus
|
on:focus
|
||||||
on:blur={onAccept}
|
on:blur={onBlur}
|
||||||
on:blur
|
on:blur
|
||||||
on:keydown={onKeydown}
|
on:keydown={onKeydown}
|
||||||
on:keydown
|
on:keydown
|
||||||
|
|
Loading…
Reference in a new issue