diff --git a/ts/components/IconButton.svelte b/ts/components/IconButton.svelte
index 6763def8f..7c02c44fe 100644
--- a/ts/components/IconButton.svelte
+++ b/ts/components/IconButton.svelte
@@ -3,9 +3,8 @@ Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
-->
+
+
diff --git a/ts/components/WithState.svelte b/ts/components/WithState.svelte
index 97d22ee4c..14657087f 100644
--- a/ts/components/WithState.svelte
+++ b/ts/components/WithState.svelte
@@ -5,14 +5,15 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
@@ -27,24 +30,32 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
- document.queryCommandState("bold")}
- let:state={active}
- let:updateState
- >
- {
- document.execCommand("bold");
- updateState(event);
- }}
- on:mount={createShortcut}
- >
- {@html boldIcon}
-
-
+
+
+ document.queryCommandState("bold")}
+ let:state={active}
+ let:updateState
+ >
+ {
+ document.execCommand("bold");
+ updateState(event);
+ }}
+ on:mount={createShortcut}
+ >
+ {@html boldIcon}
+
+
+
+
diff --git a/ts/editor/codable.ts b/ts/editor/codable.ts
index cd56d61b5..af9916555 100644
--- a/ts/editor/codable.ts
+++ b/ts/editor/codable.ts
@@ -9,6 +9,8 @@ import "codemirror/addon/fold/xml-fold";
import "codemirror/addon/edit/matchtags.js";
import "codemirror/addon/edit/closetag.js";
+import { setCodableButtons } from "./toolbar";
+
const codeMirrorOptions = {
mode: "htmlmixed",
theme: "monokai",
@@ -64,6 +66,7 @@ export class Codable extends HTMLTextAreaElement {
focus(): void {
this.codeMirror.focus();
+ setCodableButtons();
}
caretToEnd(): void {
diff --git a/ts/editor/contextKeys.ts b/ts/editor/contextKeys.ts
new file mode 100644
index 000000000..552cb9188
--- /dev/null
+++ b/ts/editor/contextKeys.ts
@@ -0,0 +1,4 @@
+// Copyright: Ankitects Pty Ltd and contributors
+// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
+
+export const inCodableKey = Symbol("inCodable");
diff --git a/ts/editor/editable.ts b/ts/editor/editable.ts
index 6a4a34081..78a2e9dd9 100644
--- a/ts/editor/editable.ts
+++ b/ts/editor/editable.ts
@@ -3,6 +3,7 @@
import { bridgeCommand } from "./lib";
import { nodeIsInline, caretToEnd, getBlockElement } from "./helpers";
+import { setEditableButtons } from "./toolbar";
function containsInlineContent(field: Element): boolean {
if (field.childNodes.length === 0) {
@@ -38,6 +39,11 @@ export class Editable extends HTMLElement {
this.setAttribute("contenteditable", "");
}
+ focus() {
+ super.focus();
+ setEditableButtons();
+ }
+
caretToEnd() {
caretToEnd(this);
}
diff --git a/ts/editor/toolbar.ts b/ts/editor/toolbar.ts
index 856d69014..ac6c18b42 100644
--- a/ts/editor/toolbar.ts
+++ b/ts/editor/toolbar.ts
@@ -7,12 +7,14 @@
*/
import { disabledKey, nightModeKey } from "components/contextKeys";
+import { inCodableKey } from "./contextKeys";
import { writable } from "svelte/store";
import EditorToolbar from "./EditorToolbar.svelte";
import "./bootstrap.css";
const disabled = writable(false);
+const inCodable = writable(false);
export function initToolbar(i18n: Promise): Promise {
let toolbarResolve: (value: EditorToolbar) => void;
@@ -27,6 +29,7 @@ export function initToolbar(i18n: Promise): Promise {
const context = new Map();
context.set(disabledKey, disabled);
+ context.set(inCodableKey, inCodable);
context.set(
nightModeKey,
document.documentElement.classList.contains("night-mode")
@@ -47,6 +50,14 @@ export function disableButtons(): void {
disabled.set(true);
}
+export function setCodableButtons(): void {
+ inCodable.set(true);
+}
+
+export function setEditableButtons(): void {
+ inCodable.set(false);
+}
+
export {
updateActiveButtons,
clearActiveButtons,