mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04:00
Add shortcut labels for ColorPicker and Latex items
This commit is contained in:
parent
3cf7db8557
commit
47809f6230
4 changed files with 38 additions and 17 deletions
|
@ -3,12 +3,16 @@ Copyright: Ankitects Pty Ltd and contributors
|
|||
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
-->
|
||||
<script lang="typescript">
|
||||
import { getContext } from "svelte";
|
||||
import { onMount, createEventDispatcher, getContext } from "svelte";
|
||||
import { nightModeKey } from "./contextKeys";
|
||||
import { mergeTooltipAndShortcut } from "./helpers";
|
||||
|
||||
export let id: string;
|
||||
export let className = "";
|
||||
export let tooltip: string;
|
||||
export let tooltip: string | undefined;
|
||||
export let shortcutLabel: string | undefined;
|
||||
|
||||
$: title = mergeTooltipAndShortcut(tooltip, shortcutLabel);
|
||||
|
||||
export let onChange: (event: Event) => void;
|
||||
|
||||
|
@ -18,11 +22,15 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
|
||||
const nightMode = getContext(nightModeKey);
|
||||
|
||||
let buttonRef: HTMLButtonElement;
|
||||
let inputRef: HTMLInputElement;
|
||||
|
||||
function delegateToInput() {
|
||||
inputRef.click();
|
||||
}
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
onMount(() => dispatch("mount", { button: buttonRef }));
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
|
@ -57,12 +65,13 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
</style>
|
||||
|
||||
<button
|
||||
bind:this={buttonRef}
|
||||
tabindex="-1"
|
||||
{id}
|
||||
class={extendClassName(className)}
|
||||
class:btn-day={!nightMode}
|
||||
class:btn-night={nightMode}
|
||||
title={tooltip}
|
||||
{title}
|
||||
on:click={delegateToInput}
|
||||
on:mousedown|preventDefault>
|
||||
<input bind:this={inputRef} type="color" on:change={onChange} />
|
||||
|
|
|
@ -3,7 +3,7 @@ Copyright: Ankitects Pty Ltd and contributors
|
|||
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
-->
|
||||
<script lang="typescript">
|
||||
import { getContext } from "svelte";
|
||||
import { onMount, createEventDispatcher, getContext } from "svelte";
|
||||
import { nightModeKey } from "./contextKeys";
|
||||
|
||||
export let id: string;
|
||||
|
@ -14,7 +14,12 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
|
||||
export let onClick: (event: MouseEvent) => void;
|
||||
|
||||
let buttonRef: HTMLButtonElement;
|
||||
|
||||
const nightMode = getContext(nightModeKey);
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
onMount(() => dispatch("mount", { button: buttonRef }));
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
|
@ -60,6 +65,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
|
||||
<button
|
||||
{id}
|
||||
bind:this={buttonRef}
|
||||
class={`btn dropdown-item ${className}`}
|
||||
class:btn-day={!nightMode}
|
||||
class:btn-night={nightMode}
|
||||
|
|
|
@ -117,20 +117,26 @@ export function getTemplateMenus(): (DynamicSvelteComponent<typeof DropdownMenu>
|
|||
];
|
||||
|
||||
const latexMenuItems = [
|
||||
dropdownItem({
|
||||
onClick: () => wrap("[latex]", "[/latex]"),
|
||||
label: tr.editingLatex(),
|
||||
endLabel: "Ctrl+T, T",
|
||||
withShortcuts({
|
||||
shortcuts: ["Control+KeyT, KeyT"],
|
||||
button: dropdownItem({
|
||||
onClick: () => wrap("[latex]", "[/latex]"),
|
||||
label: tr.editingLatex(),
|
||||
}),
|
||||
}),
|
||||
dropdownItem({
|
||||
onClick: () => wrap("[$]", "[/$]"),
|
||||
label: tr.editingLatexEquation(),
|
||||
endLabel: "Ctrl+T, E",
|
||||
withShortcuts({
|
||||
shortcuts: ["Control+KeyT, KeyE"],
|
||||
button: dropdownItem({
|
||||
onClick: () => wrap("[$]", "[/$]"),
|
||||
label: tr.editingLatexEquation(),
|
||||
}),
|
||||
}),
|
||||
dropdownItem({
|
||||
onClick: () => wrap("[$$]", "[/$$]"),
|
||||
label: tr.editingLatexMathEnv(),
|
||||
endLabel: "Ctrl+T, M",
|
||||
withShortcuts({
|
||||
shortcuts: ["Control+KeyT, KeyM"],
|
||||
button: dropdownItem({
|
||||
onClick: () => wrap("[$$]", "[/$$]"),
|
||||
label: tr.editingLatexMathEnv(),
|
||||
}),
|
||||
}),
|
||||
];
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ function check(event: KeyboardEvent, modifiersAndKey: string[]): boolean {
|
|||
);
|
||||
}
|
||||
|
||||
const shortcutTimeoutMs = 350;
|
||||
const shortcutTimeoutMs = 400;
|
||||
|
||||
function innerShortcut(
|
||||
lastEvent: KeyboardEvent,
|
||||
|
|
Loading…
Reference in a new issue