mirror of
https://github.com/ankitects/anki.git
synced 2025-11-11 15:17:12 -05:00
Setup toggleHtmlEdit on editingArea
This commit is contained in:
parent
678a5997e9
commit
8a902944a8
3 changed files with 34 additions and 9 deletions
|
|
@ -18,7 +18,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
import { wrap } from "./wrap";
|
import { wrap } from "./wrap";
|
||||||
import { appendInParentheses } from "./helpers";
|
import { appendInParentheses } from "./helpers";
|
||||||
import { toggleHtmlEdit } from "./codable";
|
import { forEditorField } from ".";
|
||||||
import { paperclipIcon, micIcon, functionIcon, xmlIcon } from "./icons";
|
import { paperclipIcon, micIcon, functionIcon, xmlIcon } from "./icons";
|
||||||
|
|
||||||
export let api = {};
|
export let api = {};
|
||||||
|
|
@ -30,6 +30,12 @@ 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() {
|
||||||
|
forEditorField([], (field) => {
|
||||||
|
field.editingArea.toggleHtmlEdit();
|
||||||
|
})
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ButtonGroup {api}>
|
<ButtonGroup {api}>
|
||||||
|
|
@ -173,7 +179,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
iconSize={70}
|
iconSize={70}
|
||||||
{active}
|
{active}
|
||||||
on:click={(event) => {
|
on:click={(event) => {
|
||||||
toggleHtmlEdit();
|
onHtmlEdit();
|
||||||
updateState(event);
|
updateState(event);
|
||||||
}}
|
}}
|
||||||
on:mount={createShortcut}
|
on:mount={createShortcut}
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,32 @@
|
||||||
|
|
||||||
import CodeMirror from "codemirror/src/codemirror"
|
import CodeMirror from "codemirror/src/codemirror"
|
||||||
|
|
||||||
const codables: Codable[] = [];
|
const codeMirrorOptions = {
|
||||||
|
lineNumbers: true,
|
||||||
export function toggleHtmlEdit() {
|
mode: "htmlmixed",
|
||||||
for (const codable of codables) {
|
|
||||||
CodeMirror.fromTextArea(codable);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Codable extends HTMLTextAreaElement {
|
export class Codable extends HTMLTextAreaElement {
|
||||||
|
codeMirror: any;
|
||||||
|
|
||||||
connectedCallback(): void {
|
connectedCallback(): void {
|
||||||
this.setAttribute("hidden", "");
|
this.setAttribute("hidden", "");
|
||||||
codables.push(this);
|
}
|
||||||
|
|
||||||
|
toggle(html: string): string {
|
||||||
|
return this.codeMirror ? this.teardown() : this.setup(html);
|
||||||
|
}
|
||||||
|
|
||||||
|
setup(html: string): string {
|
||||||
|
this.innerHTML = html;
|
||||||
|
this.codeMirror = CodeMirror.fromTextArea(this, codeMirrorOptions);
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
|
||||||
|
teardown(): string {
|
||||||
|
this.codeMirror.toTextArea();
|
||||||
|
this.codeMirror = undefined;
|
||||||
|
console.log(this.innerHTML)
|
||||||
|
return this.innerHTML;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -123,4 +123,8 @@ export class EditingArea extends HTMLDivElement {
|
||||||
blurEditable(): void {
|
blurEditable(): void {
|
||||||
this.editable.blur();
|
this.editable.blur();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toggleHtmlEdit(): void {
|
||||||
|
this.fieldHTML = this.codable.toggle(this.fieldHTML);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue