feat(CodeEditor): enable dropcursor

This commit is contained in:
sethburkart123
2024-10-02 09:21:02 +10:00
parent b6e91b2254
commit 53cfb27899
3 changed files with 27 additions and 11 deletions
@@ -5,19 +5,23 @@
import { indentOnInput, indentUnit, bracketMatching, foldKeymap, syntaxHighlighting, defaultHighlightStyle } from '@codemirror/language';
import { closeBrackets, autocompletion, closeBracketsKeymap, completionKeymap } from '@codemirror/autocomplete';
import { highlightSpecialChars, drawSelection, rectangularSelection, crosshairCursor, highlightActiveLine, keymap, EditorView } from '@codemirror/view'; // dropCursor
import { color } from '@uiw/codemirror-extensions-color'
import { Compartment } from '@codemirror/state';
// Theme
import { oneDark } from "@codemirror/theme-one-dark";
import { githubLight, githubDark } from '@uiw/codemirror-theme-github';
// Language
import { css } from "@codemirror/lang-css";
import { onDestroy, onMount } from 'svelte'
import { settingsState } from '@/seqta/utils/listeners/SettingsState'
let editor = $state<HTMLDivElement | null>(null)
let view: EditorView | null = null;
let editorTheme = new Compartment();
let { value, onChange } = $props<{value: string, onChange: (value: string) => void}>()
function createEditorState(initialContents: string, options = {oneDark: false}) {
function createEditorState(initialContents: string) {
let extensions = [
highlightSpecialChars(),
history(),
@@ -32,6 +36,7 @@
crosshairCursor(),
highlightActiveLine(),
highlightSelectionMatches(),
editorTheme.of(githubLight),
keymap.of([
indentWithTab,
...closeBracketsKeymap,
@@ -46,12 +51,10 @@
}
}),
css(),
color,
syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
];
if (options.oneDark)
extensions.push(oneDark);
return EditorState.create({
doc: initialContents,
extensions
@@ -67,6 +70,16 @@
const state = createEditorState(value);
view = createEditorView(state, editor as HTMLElement);
}
settingsState.subscribe((settings) => {
if (view) {
view.dispatch({
effects: editorTheme.reconfigure(
settings.DarkMode ? githubDark : githubLight
)
})
}
});
});
onDestroy(() => {
+7 -1
View File
@@ -44,4 +44,10 @@ input {
.cm-editor {
width: 100%;
min-height: 100px;
}
}
/* .dark .cm-editor .cm-tooltip-autocomplete {
background-color: #1e1e1e;
color: #d4d4d4;
}
*/