anki/ts/editor/EditorToolbar.svelte
Henrik Giesel c9bd39c6a2
Several editor fixes (#1478)
* Declare toolbar api via modifiable property

* Fix addon buttons

* Assign editing areas in a synchronous way

* Restore the Tab shortcut that moves the caret to end

- moveCaretToEnd is called twice now: The moveCaretToEnd calls in
  *TextInput causes the caret to be moved to the end when switching back
  from the window and back.
- To fix this, I will need the code for saving and restoring locations
  from #1377

* Restore selections in the PlainTextInput

* Improve type safety of destroyable

- clearable-array was renamed to destroyable
2021-11-05 11:29:02 +10:00

98 lines
2.8 KiB
Svelte

<!--
Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
-->
<script context="module" lang="ts">
import "./legacy.css";
import { updateAllState, resetAllState } from "../components/WithState.svelte";
import type { ButtonGroupAPI } from "../components/ButtonGroup.svelte";
import type { ButtonToolbarAPI } from "../components/ButtonToolbar.svelte";
export function updateActiveButtons(event: Event) {
updateAllState(event);
}
export function clearActiveButtons() {
resetAllState(false);
}
export interface EditorToolbarAPI {
toolbar: ButtonToolbarAPI;
notetypeButtons: ButtonGroupAPI;
formatInlineButtons: ButtonGroupAPI;
formatBlockButtons: ButtonGroupAPI;
colorButtons: ButtonGroupAPI;
templateButtons: ButtonGroupAPI;
}
/* Our dynamic components */
import AddonButtons from "./AddonButtons.svelte";
import PreviewButton from "./PreviewButton.svelte";
export const editorToolbar = {
AddonButtons,
PreviewButton,
};
</script>
<script lang="ts">
import StickyHeader from "../components/StickyHeader.svelte";
import ButtonToolbar from "../components/ButtonToolbar.svelte";
import Item from "../components/Item.svelte";
import NoteTypeButtons from "./NoteTypeButtons.svelte";
import FormatInlineButtons from "./FormatInlineButtons.svelte";
import FormatBlockButtons from "./FormatBlockButtons.svelte";
import ColorButtons from "./ColorButtons.svelte";
import TemplateButtons from "./TemplateButtons.svelte";
export let size: number;
export let wrap: boolean;
export let textColor: string;
export let highlightColor: string;
const toolbar = {};
const notetypeButtons = {};
const formatInlineButtons = {};
const formatBlockButtons = {};
const colorButtons = {};
const templateButtons = {};
export let api: Partial<EditorToolbarAPI> = {};
Object.assign(api, {
toolbar,
notetypeButtons,
formatInlineButtons,
formatBlockButtons,
colorButtons,
templateButtons,
} as EditorToolbarAPI);
</script>
<StickyHeader>
<ButtonToolbar {size} {wrap} api={toolbar}>
<Item id="notetype">
<NoteTypeButtons api={notetypeButtons} />
</Item>
<Item id="inlineFormatting">
<FormatInlineButtons api={formatInlineButtons} />
</Item>
<Item id="blockFormatting">
<FormatBlockButtons api={formatBlockButtons} />
</Item>
<Item id="color">
<ColorButtons {textColor} {highlightColor} api={colorButtons} />
</Item>
<Item id="template">
<TemplateButtons api={templateButtons} />
</Item>
</ButtonToolbar>
</StickyHeader>