@@ -4,45 +4,58 @@ import { ensoSyntax } from '@/components/CodeEditor/ensoSyntax'
44import { useEnsoSourceSync } from ' @/components/CodeEditor/sync'
55import { ensoHoverTooltip } from ' @/components/CodeEditor/tooltips'
66import CodeMirrorRoot from ' @/components/CodeMirrorRoot.vue'
7+ import VueComponentHost from ' @/components/VueComponentHost.vue'
78import { useGraphStore } from ' @/stores/graph'
89import { useProjectStore } from ' @/stores/project'
910import { useSuggestionDbStore } from ' @/stores/suggestionDatabase'
1011import { useAutoBlur } from ' @/util/autoBlur'
1112import { useCodeMirror } from ' @/util/codemirror'
13+ import { highlightStyle } from ' @/util/codemirror/highlight'
1214import { testSupport } from ' @/util/codemirror/testSupport'
13- import { indentWithTab } from ' @codemirror/commands'
14- import {
15- bracketMatching ,
16- defaultHighlightStyle ,
17- foldGutter ,
18- syntaxHighlighting ,
19- } from ' @codemirror/language'
15+ import { indentWithTab , insertNewlineKeepIndent } from ' @codemirror/commands'
16+ import { bracketMatching , foldGutter } from ' @codemirror/language'
2017import { lintGutter } from ' @codemirror/lint'
2118import { highlightSelectionMatches } from ' @codemirror/search'
2219import { keymap } from ' @codemirror/view'
23- import { type Highlighter } from ' @lezer/highlight'
2420import { minimalSetup } from ' codemirror'
25- import { computed , onMounted , useTemplateRef , type ComponentInstance } from ' vue'
21+ import {
22+ computed ,
23+ onMounted ,
24+ toRef ,
25+ useCssModule ,
26+ useTemplateRef ,
27+ type ComponentInstance ,
28+ } from ' vue'
2629
2730const projectStore = useProjectStore ()
2831const graphStore = useGraphStore ()
2932const suggestionDbStore = useSuggestionDbStore ()
33+
34+ const vueComponentHost =
35+ useTemplateRef <ComponentInstance <typeof VueComponentHost >>(' vueComponentHost' )
3036const editorRoot = useTemplateRef <ComponentInstance <typeof CodeMirrorRoot >>(' editorRoot' )
3137const rootElement = computed (() => editorRoot .value ?.rootElement )
3238useAutoBlur (rootElement )
3339
40+ const autoindentOnEnter = {
41+ key: ' Enter' ,
42+ run: insertNewlineKeepIndent ,
43+ }
44+
45+ const vueHost = computed (() => vueComponentHost .value || undefined )
3446const { editorView, setExtraExtensions } = useCodeMirror (editorRoot , {
3547 extensions: [
48+ keymap .of ([indentWithTab , autoindentOnEnter ]),
3649 minimalSetup ,
37- syntaxHighlighting (defaultHighlightStyle as Highlighter ),
3850 bracketMatching (),
3951 foldGutter (),
4052 lintGutter (),
4153 highlightSelectionMatches (),
42- ensoSyntax (),
43- ensoHoverTooltip ( graphStore , suggestionDbStore ),
44- keymap . of ([ indentWithTab ] ),
54+ ensoSyntax (toRef ( graphStore , ' moduleRoot ' ) ),
55+ highlightStyle ( useCssModule () ),
56+ ensoHoverTooltip ( graphStore , suggestionDbStore , vueHost ),
4557 ],
58+ vueHost ,
4659})
4760;(window as any ).__codeEditorApi = testSupport (editorView )
4861const { updateListener, connectModuleListener } = useEnsoSourceSync (
@@ -61,6 +74,7 @@ onMounted(() => {
6174
6275<template >
6376 <CodeMirrorRoot ref =" editorRoot" class =" CodeEditor" @keydown.tab.stop.prevent />
77+ <VueComponentHost ref =" vueComponentHost" />
6478</template >
6579
6680<style scoped>
@@ -73,7 +87,6 @@ onMounted(() => {
7387}
7488
7589:deep(.cm-scroller ) {
76- font-family : var (--font-mono );
7790 /* Prevent touchpad back gesture, which can be triggered while panning. */
7891 overscroll-behavior : none ;
7992}
@@ -113,3 +126,32 @@ onMounted(() => {
113126 min-width : 32px ;
114127}
115128 </style >
129+
130+ <!-- suppress CssUnusedSymbol -->
131+ <style module>
132+ .keyword ,
133+ .moduleKeyword ,
134+ .modifier {
135+ color : #708 ;
136+ }
137+ .number {
138+ color : #164 ;
139+ }
140+ .string {
141+ color : #a11 ;
142+ }
143+ .escape {
144+ color : #e40 ;
145+ }
146+ .variableName ,
147+ .definition-variableName {
148+ color : #00f ;
149+ }
150+ .lineComment ,
151+ .docComment {
152+ color : #940 ;
153+ }
154+ .invalid {
155+ color : #f00 ;
156+ }
157+ </style >
0 commit comments