Fix shortcuts for tag actions not working (#2214)

This commit is contained in:
Hikaru Y 2022-11-27 09:29:58 +09:00 committed by GitHub
parent b40aae7522
commit 8f2f62c466
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 18 deletions

View file

@ -6,3 +6,4 @@ export const fontSizeKey = Symbol("fontSize");
export const directionKey = Symbol("direction"); export const directionKey = Symbol("direction");
export const descriptionKey = Symbol("description"); export const descriptionKey = Symbol("description");
export const collapsedKey = Symbol("collapsed"); export const collapsedKey = Symbol("collapsed");
export const tagActionsShortcutsKey = Symbol("tagActionsShortcuts");

View file

@ -3,11 +3,13 @@ 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="ts"> <script lang="ts">
import { createEventDispatcher, tick } from "svelte"; import { createEventDispatcher, setContext, tick } from "svelte";
import type { Writable } from "svelte/store"; import type { Writable } from "svelte/store";
import { writable } from "svelte/store"; import { writable } from "svelte/store";
import Shortcut from "../components/Shortcut.svelte";
import { execCommand } from "../domlib"; import { execCommand } from "../domlib";
import { tagActionsShortcutsKey } from "../lib/context-keys";
import { isArrowDown, isArrowUp } from "../lib/keys"; import { isArrowDown, isArrowUp } from "../lib/keys";
import { Tags, tags as tagsService } from "../lib/proto"; import { Tags, tags as tagsService } from "../lib/proto";
import { TagOptionsButton } from "./tag-options-button"; import { TagOptionsButton } from "./tag-options-button";
@ -26,6 +28,15 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
export let tags: Writable<string[]>; export let tags: Writable<string[]>;
export let keyCombination: string = "Control+Shift+T"; export let keyCombination: string = "Control+Shift+T";
const selectAllShortcut = "Control+A";
const copyShortcut = "Control+C";
const removeShortcut = "Backspace";
setContext(tagActionsShortcutsKey, {
selectAllShortcut,
copyShortcut,
removeShortcut,
});
let tagTypes: TagType[]; let tagTypes: TagType[];
function tagsToTagTypes(tags: string[]): void { function tagsToTagTypes(tags: string[]): void {
tagTypes = tags.map( tagTypes = tags.map(
@ -384,6 +395,12 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
$: dispatch("heightChange", { height: height * 1.15 }); $: dispatch("heightChange", { height: height * 1.15 });
</script> </script>
{#if anyTagsSelected}
<Shortcut keyCombination={selectAllShortcut} on:action={selectAllTags} />
<Shortcut keyCombination={copyShortcut} on:action={copySelectedTags} />
<Shortcut keyCombination={removeShortcut} on:action={deleteSelectedTags} />
{/if}
<div class="tag-editor" on:focusout={deselectIfLeave} bind:offsetHeight={height}> <div class="tag-editor" on:focusout={deselectIfLeave} bind:offsetHeight={height}>
<TagOptionsButton <TagOptionsButton
bind:badgeHeight bind:badgeHeight

View file

@ -3,8 +3,9 @@ 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="ts"> <script lang="ts">
import { createEventDispatcher, onMount, tick } from "svelte"; import { createEventDispatcher, getContext, onMount, tick } from "svelte";
import { tagActionsShortcutsKey } from "../lib/context-keys";
import { isArrowLeft, isArrowRight } from "../lib/keys"; import { isArrowLeft, isArrowRight } from "../lib/keys";
import { registerShortcut } from "../lib/shortcuts"; import { registerShortcut } from "../lib/shortcuts";
import { import {
@ -234,8 +235,11 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
} }
} }
const { selectAllShortcut } =
getContext<Record<string, string>>(tagActionsShortcutsKey);
onMount(() => { onMount(() => {
registerShortcut(onSelectAll, "Control+A", { target: input }); registerShortcut(onSelectAll, selectAllShortcut, { target: input });
input.focus(); input.focus();
}); });
</script> </script>

View file

@ -3,13 +3,13 @@ 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="ts"> <script lang="ts">
import { createEventDispatcher } from "svelte"; import { createEventDispatcher, getContext } from "svelte";
import DropdownItem from "../../components/DropdownItem.svelte"; import DropdownItem from "../../components/DropdownItem.svelte";
import IconConstrain from "../../components/IconConstrain.svelte"; import IconConstrain from "../../components/IconConstrain.svelte";
import Popover from "../../components/Popover.svelte"; import Popover from "../../components/Popover.svelte";
import Shortcut from "../../components/Shortcut.svelte";
import WithFloating from "../../components/WithFloating.svelte"; import WithFloating from "../../components/WithFloating.svelte";
import { tagActionsShortcutsKey } from "../../lib/context-keys";
import * as tr from "../../lib/ftl"; import * as tr from "../../lib/ftl";
import { getPlatformString } from "../../lib/shortcuts"; import { getPlatformString } from "../../lib/shortcuts";
import { dotsIcon } from "./icons"; import { dotsIcon } from "./icons";
@ -18,9 +18,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
let show = false; let show = false;
const allShortcut = "Control+A"; const { selectAllShortcut, copyShortcut, removeShortcut } =
const copyShortcut = "Control+C"; getContext<Record<string, string>>(tagActionsShortcutsKey);
const removeShortcut = "Backspace";
</script> </script>
<WithFloating <WithFloating
@ -36,27 +35,18 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
<Popover slot="floating"> <Popover slot="floating">
<DropdownItem on:click={() => dispatch("tagselectall")}> <DropdownItem on:click={() => dispatch("tagselectall")}>
{tr.editingTagsSelectAll()} ({getPlatformString(allShortcut)}) {tr.editingTagsSelectAll()} ({getPlatformString(selectAllShortcut)})
</DropdownItem> </DropdownItem>
<Shortcut
keyCombination={allShortcut}
on:action={() => dispatch("tagselectall")}
/>
<DropdownItem on:click={() => dispatch("tagcopy")} <DropdownItem on:click={() => dispatch("tagcopy")}
>{tr.editingTagsCopy()} ({getPlatformString(copyShortcut)})</DropdownItem >{tr.editingTagsCopy()} ({getPlatformString(copyShortcut)})</DropdownItem
> >
<Shortcut keyCombination={copyShortcut} on:action={() => dispatch("tagcopy")} />
<DropdownItem on:click={() => dispatch("tagdelete")} <DropdownItem on:click={() => dispatch("tagdelete")}
>{tr.editingTagsRemove()} ({getPlatformString( >{tr.editingTagsRemove()} ({getPlatformString(
removeShortcut, removeShortcut,
)})</DropdownItem )})</DropdownItem
> >
<Shortcut
keyCombination={removeShortcut}
on:action={() => dispatch("tagdelete")}
/>
</Popover> </Popover>
</WithFloating> </WithFloating>