select all tags with Ctrl+A (#1847)

This commit is contained in:
BlueGreenMagick 2022-05-10 10:39:54 +09:00 committed by GitHub
parent 1b48d3e3d1
commit 68482d37a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View file

@ -112,6 +112,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
function appendEmptyTag(): void {
// used by tag badge and tag spacer
deselect();
const lastTag = tagTypes[tagTypes.length - 1];
if (!lastTag || lastTag.name.length > 0) {
@ -448,6 +449,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
splitTag(index, detail.start, detail.end)}
on:tagadd={() => insertTagKeepFocus(index)}
on:tagdelete={() => deleteTagAt(index)}
on:tagselectall={selectAllTags}
on:tagjoinprevious={() => joinWithPreviousTag(index)}
on:tagjoinnext={() => joinWithNextTag(index)}
on:tagmoveprevious={() => moveToPreviousTag(index)}

View file

@ -5,6 +5,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
<script lang="ts">
import { createEventDispatcher, onMount, tick } from "svelte";
import { registerShortcut } from "../../lib/shortcuts";
import {
delimChar,
normalizeTagname,
@ -230,7 +231,20 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
name = last;
}
onMount(() => input.focus());
async function onSelectAll(event: KeyboardEvent) {
if (name.length === 0) {
input.blur();
await tick(); // ensure blur events are processed before tagselectall
dispatch("tagselectall");
event.preventDefault();
event.stopPropagation();
}
}
onMount(() => {
registerShortcut(onSelectAll, "Control+A", { target: input });
input.focus();
});
</script>
<input