1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2025-07-15 12:54:06 +00:00

Use objecteditor throughout the app

This commit is contained in:
2023-05-29 20:51:54 +02:00
parent 035d5211d9
commit 890dac30ed
4 changed files with 106 additions and 36 deletions

View File

@ -5,9 +5,13 @@
import { EditorState } from '@codemirror/state';
import { EditorView, keymap } from '@codemirror/view';
import { basicSetup } from 'codemirror';
import { onMount } from 'svelte';
import { createEventDispatcher, onMount } from 'svelte';
export let text = '';
export let editor = undefined;
const dispatch = createEventDispatcher();
let editorParent;
const editorState = EditorState.create({
doc: '',
@ -17,17 +21,14 @@
javascript(),
EditorState.tabSize.of(4),
EditorView.updateListener.of(e => {
// if (!e.docChanged) {
// return;
// }
if (!e.docChanged) {
return;
}
text = e.state.doc.toString();
}),
],
});
let editorParent;
let editor;
onMount(() => {
editor = new EditorView({
parent: editorParent,
@ -37,10 +38,12 @@
editor.dispatch({
changes: {
from: 0,
to: editorState.doc.length,
to: editor.state.doc.length,
insert: text,
},
});
dispatch('inited', { editor });
});
</script>
@ -49,9 +52,11 @@
<style>
.editor {
width: 100%;
background-color: #fff;
}
.editor :global(.cm-editor) {
overflow: auto;
height: 100%;
}
</style>