mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
Move other buttons to WithShortcut
This commit is contained in:
parent
85f89dc111
commit
d2ca94a29d
8 changed files with 94 additions and 79 deletions
|
@ -311,22 +311,6 @@ $editorToolbar.addButtonGroup({{
|
|||
def setupShortcuts(self) -> None:
|
||||
# if a third element is provided, enable shortcut even when no field selected
|
||||
cuts: List[Tuple] = [
|
||||
("Ctrl+L", self.onCardLayout, True),
|
||||
("Ctrl++", self.toggleSuper),
|
||||
("Ctrl+=", self.toggleSub),
|
||||
("F7", self.onForeground),
|
||||
("F8", self.onChangeCol),
|
||||
("Ctrl+Shift+C", self.onCloze),
|
||||
("Ctrl+Shift+Alt+C", self.onCloze),
|
||||
("F3", self.onAddMedia),
|
||||
("F5", self.onRecSound),
|
||||
("Ctrl+T, T", self.insertLatex),
|
||||
("Ctrl+T, E", self.insertLatexEqn),
|
||||
("Ctrl+T, M", self.insertLatexMathEnv),
|
||||
("Ctrl+M, M", self.insertMathjaxInline),
|
||||
("Ctrl+M, E", self.insertMathjaxBlock),
|
||||
("Ctrl+M, C", self.insertMathjaxChemistry),
|
||||
("Ctrl+Shift+X", self.onHtmlEdit),
|
||||
("Ctrl+Shift+T", self.onFocusTags, True),
|
||||
]
|
||||
gui_hooks.editor_did_init_shortcuts(cuts, self)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
import type { ToolbarItem } from "./types";
|
||||
|
||||
export interface WithShortcutProps {
|
||||
export interface WithShortcutsProps {
|
||||
button: ToolbarItem;
|
||||
shortcut: string;
|
||||
shortcuts: string[];
|
||||
}
|
|
@ -10,7 +10,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
import { registerShortcut } from "anki/shortcuts";
|
||||
|
||||
export let button: ToolbarItem;
|
||||
export let shortcut: string;
|
||||
export let shortcuts: string[];
|
||||
|
||||
function extend({ ...rest }: DynamicSvelteComponent): DynamicSvelteComponent {
|
||||
return {
|
||||
|
@ -18,17 +18,19 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
};
|
||||
}
|
||||
|
||||
let deregister;
|
||||
let deregister: (() => void)[];
|
||||
|
||||
function createShortcut({ detail }: CustomEvent): void {
|
||||
const mounted: HTMLButtonElement = detail.button;
|
||||
deregister = registerShortcut((event) => {
|
||||
mounted.dispatchEvent(new MouseEvent("click"));
|
||||
event.preventDefault();
|
||||
}, shortcut);
|
||||
deregisters = shortcuts.map((shortcut: string): (() => void) =>
|
||||
registerShortcut((event) => {
|
||||
mounted.dispatchEvent(new MouseEvent("click"));
|
||||
event.preventDefault();
|
||||
}, shortcut)
|
||||
);
|
||||
}
|
||||
|
||||
onDestroy(() => deregister());
|
||||
onDestroy(() => deregisters.map((dereg) => dereg()));
|
||||
</script>
|
||||
|
||||
<svelte:component
|
|
@ -20,8 +20,8 @@ import type { DropdownItemProps } from "./DropdownItem";
|
|||
import WithDropdownMenu from "./WithDropdownMenu.svelte";
|
||||
import type { WithDropdownMenuProps } from "./WithDropdownMenu";
|
||||
|
||||
import WithShortcut from "./WithShortcut.svelte";
|
||||
import type { WithShortcutProps } from "./WithShortcut";
|
||||
import WithShortcuts from "./WithShortcuts.svelte";
|
||||
import type { WithShortcutsProps } from "./WithShortcuts";
|
||||
|
||||
import { dynamicComponent } from "sveltelib/dynamicComponent";
|
||||
|
||||
|
@ -59,6 +59,6 @@ export const withDropdownMenu = dynamicComponent<
|
|||
WithDropdownMenuProps
|
||||
>(WithDropdownMenu);
|
||||
|
||||
export const withShortcut = dynamicComponent<typeof WithShortcut, WithShortcutProps>(
|
||||
WithShortcut
|
||||
export const withShortcuts = dynamicComponent<typeof WithShortcuts, WithShortcutsProps>(
|
||||
WithShortcuts
|
||||
);
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
// Copyright: Ankitects Pty Ltd and contributors
|
||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
import type IconButton from "editor-toolbar/IconButton.svelte";
|
||||
import type { IconButtonProps } from "editor-toolbar/IconButton";
|
||||
import type WithShortcuts from "editor-toolbar/WithShortcuts.svelte";
|
||||
import type { WithShortcutsProps } from "editor-toolbar/WithShortcuts";
|
||||
import type { DynamicSvelteComponent } from "sveltelib/dynamicComponent";
|
||||
|
||||
import * as tr from "anki/i18n";
|
||||
import { iconButton } from "editor-toolbar/dynamicComponents";
|
||||
import { iconButton, withShortcuts } from "editor-toolbar/dynamicComponents";
|
||||
|
||||
import bracketsIcon from "./code-brackets.svg";
|
||||
|
||||
|
@ -40,12 +40,15 @@ function onCloze(event: MouseEvent): void {
|
|||
wrap(`{{c${highestCloze}::`, "}}");
|
||||
}
|
||||
|
||||
export function getClozeButton(): DynamicSvelteComponent<typeof IconButton> &
|
||||
IconButtonProps {
|
||||
return iconButton({
|
||||
id: "cloze",
|
||||
icon: bracketsIcon,
|
||||
onClick: onCloze,
|
||||
tooltip: tr.editingClozeDeletionCtrlandshiftandc(),
|
||||
export function getClozeButton(): DynamicSvelteComponent<typeof WithShortcuts> &
|
||||
WithShortcutsProps {
|
||||
return withShortcuts({
|
||||
shortcuts: ["Control+Shift+KeyC", "Control+Alt+Shift+KeyC"],
|
||||
button: iconButton({
|
||||
id: "cloze",
|
||||
icon: bracketsIcon,
|
||||
onClick: onCloze,
|
||||
tooltip: tr.editingClozeDeletionCtrlandshiftandc(),
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
|
|
@ -4,7 +4,12 @@ import type ButtonGroup from "editor-toolbar/ButtonGroup.svelte";
|
|||
import type { ButtonGroupProps } from "editor-toolbar/ButtonGroup";
|
||||
import type { DynamicSvelteComponent } from "sveltelib/dynamicComponent";
|
||||
|
||||
import { iconButton, colorPicker, buttonGroup } from "editor-toolbar/dynamicComponents";
|
||||
import {
|
||||
iconButton,
|
||||
colorPicker,
|
||||
buttonGroup,
|
||||
withShortcuts,
|
||||
} from "editor-toolbar/dynamicComponents";
|
||||
import * as tr from "anki/i18n";
|
||||
|
||||
import squareFillIcon from "./square-fill.svg";
|
||||
|
@ -26,17 +31,23 @@ function wrapWithForecolor(color: string): void {
|
|||
|
||||
export function getColorGroup(): DynamicSvelteComponent<typeof ButtonGroup> &
|
||||
ButtonGroupProps {
|
||||
const forecolorButton = iconButton({
|
||||
icon: squareFillIcon,
|
||||
className: "forecolor",
|
||||
onClick: () => wrapWithForecolor(getForecolor()),
|
||||
tooltip: tr.editingSetForegroundColourF7(),
|
||||
const forecolorButton = withShortcuts({
|
||||
shortcuts: ["F7"],
|
||||
button: iconButton({
|
||||
icon: squareFillIcon,
|
||||
className: "forecolor",
|
||||
onClick: () => wrapWithForecolor(getForecolor()),
|
||||
tooltip: tr.editingSetForegroundColourF7(),
|
||||
}),
|
||||
});
|
||||
|
||||
const colorpickerButton = colorPicker({
|
||||
onChange: ({ currentTarget }) =>
|
||||
setForegroundColor((currentTarget as HTMLInputElement).value),
|
||||
tooltip: tr.editingChangeColourF8(),
|
||||
const colorpickerButton = withShortcuts({
|
||||
shortcuts: ["F8"],
|
||||
button: colorPicker({
|
||||
onChange: ({ currentTarget }) =>
|
||||
setForegroundColor((currentTarget as HTMLInputElement).value),
|
||||
tooltip: tr.editingChangeColourF8(),
|
||||
}),
|
||||
});
|
||||
|
||||
return buttonGroup({
|
||||
|
|
|
@ -9,7 +9,7 @@ import {
|
|||
commandIconButton,
|
||||
iconButton,
|
||||
buttonGroup,
|
||||
withShortcut,
|
||||
withShortcuts,
|
||||
} from "editor-toolbar/dynamicComponents";
|
||||
|
||||
import boldIcon from "./type-bold.svg";
|
||||
|
@ -21,8 +21,8 @@ import eraserIcon from "./eraser.svg";
|
|||
|
||||
export function getFormatInlineGroup(): DynamicSvelteComponent<typeof ButtonGroup> &
|
||||
ButtonGroupProps {
|
||||
const boldButton = withShortcut({
|
||||
shortcut: "Control+KeyB",
|
||||
const boldButton = withShortcuts({
|
||||
shortcuts: ["Control+KeyB"],
|
||||
button: commandIconButton({
|
||||
icon: boldIcon,
|
||||
tooltip: tr.editingBoldTextCtrlandb(),
|
||||
|
@ -30,8 +30,8 @@ export function getFormatInlineGroup(): DynamicSvelteComponent<typeof ButtonGrou
|
|||
}),
|
||||
});
|
||||
|
||||
const italicButton = withShortcut({
|
||||
shortcut: "Control+KeyI",
|
||||
const italicButton = withShortcuts({
|
||||
shortcuts: ["Control+KeyI"],
|
||||
button: commandIconButton({
|
||||
icon: italicIcon,
|
||||
tooltip: tr.editingItalicTextCtrlandi(),
|
||||
|
@ -39,8 +39,8 @@ export function getFormatInlineGroup(): DynamicSvelteComponent<typeof ButtonGrou
|
|||
}),
|
||||
});
|
||||
|
||||
const underlineButton = withShortcut({
|
||||
shortcut: "Control+KeyU",
|
||||
const underlineButton = withShortcuts({
|
||||
shortcuts: ["Control+KeyU"],
|
||||
button: commandIconButton({
|
||||
icon: underlineIcon,
|
||||
tooltip: tr.editingUnderlineTextCtrlandu(),
|
||||
|
@ -48,20 +48,26 @@ export function getFormatInlineGroup(): DynamicSvelteComponent<typeof ButtonGrou
|
|||
}),
|
||||
});
|
||||
|
||||
const superscriptButton = commandIconButton({
|
||||
icon: superscriptIcon,
|
||||
tooltip: tr.editingSuperscriptCtrlandand(),
|
||||
command: "superscript",
|
||||
const superscriptButton = withShortcuts({
|
||||
shortcuts: ["Control+Shift+Equal"],
|
||||
button: commandIconButton({
|
||||
icon: superscriptIcon,
|
||||
tooltip: tr.editingSuperscriptCtrlandand(),
|
||||
command: "superscript",
|
||||
}),
|
||||
});
|
||||
|
||||
const subscriptButton = commandIconButton({
|
||||
icon: subscriptIcon,
|
||||
tooltip: tr.editingSubscriptCtrland(),
|
||||
command: "subscript",
|
||||
const subscriptButton = withShortcuts({
|
||||
shortcuts: ["Control+Equal"],
|
||||
button: commandIconButton({
|
||||
icon: subscriptIcon,
|
||||
tooltip: tr.editingSubscriptCtrland(),
|
||||
command: "subscript",
|
||||
}),
|
||||
});
|
||||
|
||||
const removeFormatButton = withShortcut({
|
||||
shortcut: "Control+KeyR",
|
||||
const removeFormatButton = withShortcuts({
|
||||
shortcuts: ["Control+KeyR"],
|
||||
button: iconButton({
|
||||
icon: eraserIcon,
|
||||
tooltip: tr.editingRemoveFormattingCtrlandr(),
|
||||
|
|
|
@ -13,6 +13,7 @@ import {
|
|||
dropdownMenu,
|
||||
dropdownItem,
|
||||
buttonGroup,
|
||||
withShortcuts,
|
||||
} from "editor-toolbar/dynamicComponents";
|
||||
import * as tr from "anki/i18n";
|
||||
|
||||
|
@ -41,21 +42,26 @@ const mathjaxMenuId = "mathjaxMenu";
|
|||
|
||||
export function getTemplateGroup(): DynamicSvelteComponent<typeof ButtonGroup> &
|
||||
ButtonGroupProps {
|
||||
const attachmentButton = iconButton({
|
||||
icon: paperclipIcon,
|
||||
onClick: onAttachment,
|
||||
tooltip: tr.editingAttachPicturesaudiovideoF3(),
|
||||
const attachmentButton = withShortcuts({
|
||||
shortcuts: ["F3"],
|
||||
button: iconButton({
|
||||
icon: paperclipIcon,
|
||||
onClick: onAttachment,
|
||||
tooltip: tr.editingAttachPicturesaudiovideoF3(),
|
||||
}),
|
||||
});
|
||||
|
||||
const recordButton = iconButton({
|
||||
icon: micIcon,
|
||||
onClick: onRecord,
|
||||
tooltip: tr.editingRecordAudioF5(),
|
||||
const recordButton = withShortcuts({
|
||||
shortcuts: ["F5"],
|
||||
button: iconButton({
|
||||
icon: micIcon,
|
||||
onClick: onRecord,
|
||||
tooltip: tr.editingRecordAudioF5(),
|
||||
}),
|
||||
});
|
||||
|
||||
const mathjaxButton = iconButton({
|
||||
icon: functionIcon,
|
||||
foo: 5,
|
||||
});
|
||||
|
||||
const mathjaxButtonWithMenu = withDropdownMenu({
|
||||
|
@ -63,10 +69,13 @@ export function getTemplateGroup(): DynamicSvelteComponent<typeof ButtonGroup> &
|
|||
menuId: mathjaxMenuId,
|
||||
});
|
||||
|
||||
const htmlButton = iconButton({
|
||||
icon: xmlIcon,
|
||||
onClick: onHtmlEdit,
|
||||
tooltip: tr.editingHtmlEditor,
|
||||
const htmlButton = withShortcuts({
|
||||
shortcuts: ["Control+Shift+KeyX"],
|
||||
button: iconButton({
|
||||
icon: xmlIcon,
|
||||
onClick: onHtmlEdit,
|
||||
tooltip: tr.editingHtmlEditor(),
|
||||
}),
|
||||
});
|
||||
|
||||
return buttonGroup({
|
||||
|
|
Loading…
Reference in a new issue