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

View file

@ -3,8 +3,17 @@
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 {
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';
@import 'ts/sass/codemirror/codemirror';
anki-editable {
display: block;
overflow-wrap: break-word;