From b0a2884f192d0c3f5b1a70ffd4fd70305a24f070 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 6 Apr 2022 11:08:32 +1000 Subject: [PATCH] Revert "Speed up editor by lazily loading CodeMirror (#1766)" This reverts commit 0db921dd3914a9cea9d56ac2fbc702a8ef5b4ee5. This caused a regression that needs looking into: https://github.com/ankitects/anki/issues/1775 --- ts/editor/CodeMirror.svelte | 2 -- ts/editor/code-mirror.ts | 25 +++++-------------- .../plain-text-input/PlainTextInput.svelte | 8 +----- 3 files changed, 7 insertions(+), 28 deletions(-) diff --git a/ts/editor/CodeMirror.svelte b/ts/editor/CodeMirror.svelte index d2859ee10..204d22161 100644 --- a/ts/editor/CodeMirror.svelte +++ b/ts/editor/CodeMirror.svelte @@ -30,7 +30,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html export let configuration: CodeMirrorLib.EditorConfiguration; export let code: Writable; - export let hidden = false; const defaultConfiguration = { rtlMoveVisually: true, @@ -80,7 +79,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html use:openCodeMirror={{ configuration: { ...configuration, ...defaultConfiguration }, resolve, - hidden, }} /> diff --git a/ts/editor/code-mirror.ts b/ts/editor/code-mirror.ts index 91d8f0ef3..f9dbb9d3e 100644 --- a/ts/editor/code-mirror.ts +++ b/ts/editor/code-mirror.ts @@ -63,37 +63,24 @@ export function focusAndSetCaret( interface OpenCodeMirrorOptions { configuration: CodeMirror.EditorConfiguration; resolve(editor: CodeMirror.EditorFromTextArea): void; - hidden: boolean; } export function openCodeMirror( textarea: HTMLTextAreaElement, - options: Partial, + { configuration, resolve }: Partial, ): { update: (options: Partial) => void; destroy: () => void } { - let editor: CodeMirror.EditorFromTextArea; + const editor = CodeMirror.fromTextArea(textarea, configuration); + resolve?.(editor); - function update({ - configuration, - resolve, - hidden, - }: Partial): void { - if (editor) { + return { + update({ configuration }: Partial): void { for (const key in configuration) { editor.setOption( key as keyof CodeMirror.EditorConfiguration, configuration[key], ); } - } else if (!hidden) { - editor = CodeMirror.fromTextArea(textarea, configuration); - resolve?.(editor); - } - } - - update(options); - - return { - update, + }, destroy(): void { editor.toTextArea(); }, diff --git a/ts/editor/plain-text-input/PlainTextInput.svelte b/ts/editor/plain-text-input/PlainTextInput.svelte index c639ffa76..7556d9364 100644 --- a/ts/editor/plain-text-input/PlainTextInput.svelte +++ b/ts/editor/plain-text-input/PlainTextInput.svelte @@ -136,13 +136,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html class:hidden on:focusin={() => ($focusedInput = api)} > - +