Connect HtmlEditButton to codable

This commit is contained in:
Henrik Giesel 2021-06-17 15:30:05 +02:00
parent 8b15c81d34
commit 678a5997e9
3 changed files with 34 additions and 16 deletions

View file

@ -13,10 +13,12 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import DropdownItem from "components/DropdownItem.svelte"; import DropdownItem from "components/DropdownItem.svelte";
import WithDropdownMenu from "components/WithDropdownMenu.svelte"; import WithDropdownMenu from "components/WithDropdownMenu.svelte";
import WithShortcut from "components/WithShortcut.svelte"; import WithShortcut from "components/WithShortcut.svelte";
import WithState from "components/WithState.svelte";
import ClozeButton from "./ClozeButton.svelte"; import ClozeButton from "./ClozeButton.svelte";
import { wrap } from "./wrap"; import { wrap } from "./wrap";
import { appendInParentheses } from "./helpers"; import { appendInParentheses } from "./helpers";
import { toggleHtmlEdit } from "./codable";
import { paperclipIcon, micIcon, functionIcon, xmlIcon } from "./icons"; import { paperclipIcon, micIcon, functionIcon, xmlIcon } from "./icons";
export let api = {}; export let api = {};
@ -28,10 +30,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
function onRecord(): void { function onRecord(): void {
bridgeCommand("record"); bridgeCommand("record");
} }
function onHtmlEdit(): void {
bridgeCommand("htmlEdit");
}
</script> </script>
<ButtonGroup {api}> <ButtonGroup {api}>
@ -164,14 +162,25 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
<ButtonGroupItem> <ButtonGroupItem>
<WithShortcut shortcut={"Control+Shift+X"} let:createShortcut let:shortcutLabel> <WithShortcut shortcut={"Control+Shift+X"} let:createShortcut let:shortcutLabel>
<WithState
key="htmledit"
update={(event) => { console.log(event); return true }}
let:state={active}
let:updateState
>
<IconButton <IconButton
tooltip={appendInParentheses(tr.editingHtmlEditor(), shortcutLabel)} tooltip={appendInParentheses(tr.editingHtmlEditor(), shortcutLabel)}
iconSize={70} iconSize={70}
on:click={onHtmlEdit} {active}
on:click={(event) => {
toggleHtmlEdit();
updateState(event);
}}
on:mount={createShortcut} on:mount={createShortcut}
> >
{@html xmlIcon} {@html xmlIcon}
</IconButton> </IconButton>
</WithState>
</WithShortcut> </WithShortcut>
</ButtonGroupItem> </ButtonGroupItem>
</ButtonGroup> </ButtonGroup>

View file

@ -3,8 +3,17 @@
import CodeMirror from "codemirror/src/codemirror" import CodeMirror from "codemirror/src/codemirror"
const codables: Codable[] = [];
export function toggleHtmlEdit() {
for (const codable of codables) {
CodeMirror.fromTextArea(codable);
}
}
export class Codable extends HTMLTextAreaElement { export class Codable extends HTMLTextAreaElement {
connectedCallback(): void { connectedCallback(): void {
CodeMirror.fromTextArea(this); this.setAttribute("hidden", "");
codables.push(this);
} }
} }

View file

@ -1,7 +1,7 @@
@import 'ts/sass/codemirror/codemirror';
@use 'ts/sass/scrollbar'; @use 'ts/sass/scrollbar';
@import 'ts/sass/codemirror/codemirror';
anki-editable { anki-editable {
display: block; display: block;
overflow-wrap: break-word; overflow-wrap: break-word;