anki/ts/editor/formatInline.ts

92 lines
2.6 KiB
TypeScript
Raw Normal View History

2021-04-15 15:59:52 +02:00
// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import type ButtonGroup from "editor-toolbar/ButtonGroup.svelte";
import type { ButtonGroupProps } from "editor-toolbar/ButtonGroup";
import type { DynamicSvelteComponent } from "sveltelib/dynamicComponent";
import * as tr from "anki/i18n";
import {
commandIconButton,
iconButton,
buttonGroup,
withShortcut,
} from "editor-toolbar/dynamicComponents";
2021-03-29 21:05:30 +02:00
import boldIcon from "./type-bold.svg";
import italicIcon from "./type-italic.svg";
import underlineIcon from "./type-underline.svg";
import superscriptIcon from "./format-superscript.svg";
import subscriptIcon from "./format-subscript.svg";
import eraserIcon from "./eraser.svg";
export function getFormatInlineGroup(): DynamicSvelteComponent<typeof ButtonGroup> &
2021-04-15 14:58:13 +02:00
ButtonGroupProps {
const boldButton = withShortcut({
shortcut: "Control+KeyB",
button: commandIconButton({
icon: boldIcon,
tooltip: tr.editingBoldText(),
command: "bold",
}),
});
2021-03-29 21:05:30 +02:00
const italicButton = withShortcut({
shortcut: "Control+KeyI",
button: commandIconButton({
icon: italicIcon,
tooltip: tr.editingItalicText(),
command: "italic",
}),
});
const underlineButton = withShortcut({
shortcut: "Control+KeyU",
button: commandIconButton({
icon: underlineIcon,
tooltip: tr.editingUnderlineText(),
command: "underline",
}),
});
2021-03-29 21:05:30 +02:00
const superscriptButton = withShortcut({
shortcut: "Control+Shift+Equal",
2021-04-22 03:25:31 +02:00
button: commandIconButton({
icon: superscriptIcon,
tooltip: tr.editingSuperscript(),
2021-04-22 03:25:31 +02:00
command: "superscript",
}),
});
const subscriptButton = withShortcut({
shortcut: "Control+Equal",
2021-04-22 03:25:31 +02:00
button: commandIconButton({
icon: subscriptIcon,
tooltip: tr.editingSubscript(),
2021-04-22 03:25:31 +02:00
command: "subscript",
}),
});
2021-03-29 21:05:30 +02:00
const removeFormatButton = withShortcut({
shortcut: "Control+KeyR",
button: iconButton({
icon: eraserIcon,
tooltip: tr.editingRemoveFormatting(),
onClick: () => {
document.execCommand("removeFormat");
},
}),
});
return buttonGroup({
2021-04-19 16:31:35 +02:00
id: "inlineFormatting",
buttons: [
boldButton,
italicButton,
underlineButton,
superscriptButton,
subscriptButton,
removeFormatButton,
],
});
}