mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 07:22:23 -04:00
Revert "Speed up editor by lazily loading CodeMirror (#1766)"
This reverts commit 0db921dd39
.
This caused a regression that needs looking into:
https://github.com/ankitects/anki/issues/1775
This commit is contained in:
parent
c96ef8cd0a
commit
b0a2884f19
3 changed files with 7 additions and 28 deletions
|
@ -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<string>;
|
||||
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,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
|
|
@ -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<OpenCodeMirrorOptions>,
|
||||
{ configuration, resolve }: Partial<OpenCodeMirrorOptions>,
|
||||
): { update: (options: Partial<OpenCodeMirrorOptions>) => void; destroy: () => void } {
|
||||
let editor: CodeMirror.EditorFromTextArea;
|
||||
const editor = CodeMirror.fromTextArea(textarea, configuration);
|
||||
resolve?.(editor);
|
||||
|
||||
function update({
|
||||
configuration,
|
||||
resolve,
|
||||
hidden,
|
||||
}: Partial<OpenCodeMirrorOptions>): void {
|
||||
if (editor) {
|
||||
return {
|
||||
update({ configuration }: Partial<OpenCodeMirrorOptions>): 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();
|
||||
},
|
||||
|
|
|
@ -136,13 +136,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
class:hidden
|
||||
on:focusin={() => ($focusedInput = api)}
|
||||
>
|
||||
<CodeMirror
|
||||
{configuration}
|
||||
{code}
|
||||
{hidden}
|
||||
bind:api={codeMirror}
|
||||
on:change={onChange}
|
||||
/>
|
||||
<CodeMirror {configuration} {code} bind:api={codeMirror} on:change={onChange} />
|
||||
</div>
|
||||
|
||||
<style lang="scss">
|
||||
|
|
Loading…
Reference in a new issue