Skip to content

Commit 7d5deb0

Browse files
committed
fix: Seems highlighting works now
1 parent 7286703 commit 7d5deb0

File tree

7 files changed

+58
-43
lines changed

7 files changed

+58
-43
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
},
3636
"dependencies": {
3737
"@babel/runtime": "^7.26.10",
38+
"@codemirror/lang-javascript": "^6.2.3",
3839
"@codemirror/autocomplete": "^6.18.6",
3940
"@codemirror/commands": "^6.8.0",
4041
"@codemirror/language": "^6.10.8",

playground/app.vue

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { javascript } from '@codemirror/lang-javascript'
33
import type { ViewUpdate } from '@codemirror/view'
44
import { lineNumbersRelative } from '@uiw/codemirror-extensions-line-numbers-relative'
5+
import { defaultHighlightStyle, syntaxHighlighting } from '@codemirror/language'
56
import type { CodeMirrorRef, Statistics } from '../src/runtime/types/nuxt-codemirror'
67
78
const code = ref('console.log("Hello, CodeMirror!");')
@@ -37,23 +38,23 @@ onMounted(() => {
3738
</script>
3839

3940
<template>
40-
<NuxtCodeMirror
41-
ref="codemirror"
42-
v-model="code"
43-
:extensions="[lineNumbersRelative, javascript()]"
44-
style="width: 500px; height: 400px;"
45-
placeholder="Enter your code here..."
46-
:auto-focus="true"
47-
:basic-setup="true"
48-
:editable="true"
49-
:indent-with-tab="true"
50-
@on-change="handleChange"
51-
@statistics="handleStatistics"
52-
@on-update="handleUpdate"
53-
/>
54-
<div>{{ code }}</div>
55-
<input
56-
v-model="code"
57-
type="text"
58-
>
41+
<NuxtCodeMirror
42+
ref="codemirror"
43+
v-model="code"
44+
style="width: 500px; height: 400px;"
45+
placeholder="Enter your code here..."
46+
:auto-focus="true"
47+
:editable="true"
48+
:extensions="[javascript()]"
49+
:basic-setup="true"
50+
:indent-with-tab="true"
51+
@on-change="handleChange"
52+
@statistics="handleStatistics"
53+
@on-update="handleUpdate"
54+
/>
55+
<div>{{ code }}</div>
56+
<input
57+
v-model="code"
58+
type="text"
59+
>
5960
</template>

playground/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
"@codemirror/search": "^6.5.10",
2020
"@codemirror/state": "6.5.2",
2121
"@codemirror/view": "6.36.4",
22-
"codemirror": "^6.0.1",
2322
"nuxt": "^3.16.0"
2423
}
2524
}

playground/pnpm-lock.yaml

Lines changed: 0 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-lock.yaml

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/runtime/composables/useNuxtCodeMirror.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import { javascript } from '@codemirror/lang-javascript';
12
import { Annotation, EditorState, StateEffect, type Extension } from '@codemirror/state'
23
import { EditorView, type ViewUpdate } from '@codemirror/view'
34
import { getDefaultExtensions } from '../getDefaultExtensions'
45
import type { UseCodeMirrorProps } from '../types/nuxt-codemirror'
56
import { getStatistics } from '../utils/utils'
67
import { watch, watchEffect } from '#imports'
8+
import { defaultHighlightStyle, syntaxHighlighting } from '@codemirror/language'
79

810
const External = Annotation.define<boolean>()
911

@@ -88,11 +90,14 @@ export function useNuxtCodeMirror(props: UseCodeMirrorProps) {
8890
basicSetup: defaultBasicSetup,
8991
})
9092

91-
let getExtensions = [updateListener, defaultThemeOption, ...defaultExtensions]
93+
// const x = syntaxHighlighting(defaultHighlightStyle)
94+
95+
let getExtensions = [defaultExtensions, updateListener, defaultThemeOption]
9296

9397
if (onUpdate && typeof onUpdate === 'function') {
9498
getExtensions.push(EditorView.updateListener.of(onUpdate))
9599
}
100+
96101
getExtensions = getExtensions.concat(extensions)
97102

98103
watchEffect(() => {

src/runtime/getDefaultExtensions.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ export const minimalSetup: Extension = (() => [
7777
highlightSpecialChars(),
7878
history(),
7979
drawSelection(),
80-
syntaxHighlighting(defaultHighlightStyle, {fallback: true}),
80+
syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
8181
keymap.of([
8282
...defaultKeymap,
8383
...historyKeymap,
84-
])
84+
]),
8585
])()
8686

8787
/**
@@ -122,7 +122,7 @@ export const basicSetup = (options: BasicSetupOptions = {}): Extension[] => {
122122
if (options.allowMultipleSelections !== false) extensions.push(EditorState.allowMultipleSelections.of(true))
123123
if (options.indentOnInput !== false) extensions.push(indentOnInput())
124124
if (options.syntaxHighlighting !== false)
125-
extensions.push(syntaxHighlighting(defaultHighlightStyle, { fallback: true }))
125+
extensions.push(syntaxHighlighting(defaultHighlightStyle))
126126
if (options.bracketMatching !== false) extensions.push(bracketMatching())
127127
if (options.closeBrackets !== false) extensions.push(closeBrackets())
128128
if (options.autocompletion !== false) extensions.push(autocompletion())
@@ -151,10 +151,10 @@ export const getDefaultExtensions = (optios: DefaultExtensionsOptions = {}): Ext
151151
}
152152
if (defaultBasicSetup) {
153153
if (typeof defaultBasicSetup === 'boolean') {
154-
getExtensions.unshift(...basicSetup())
154+
getExtensions.push(basicSetup())
155155
}
156156
else {
157-
getExtensions.unshift(...basicSetup(defaultBasicSetup))
157+
getExtensions.unshift(minimalSetup)
158158
}
159159
}
160160
if (placeholderStr) {
@@ -180,5 +180,5 @@ export const getDefaultExtensions = (optios: DefaultExtensionsOptions = {}): Ext
180180
getExtensions.push(EditorState.readOnly.of(true))
181181
}
182182

183-
return [...getExtensions]
183+
return getExtensions
184184
}

0 commit comments

Comments
 (0)