Skip to content

Commit d9e6ffc

Browse files
authored
Merge pull request #31 from ut-code/syntax_highlight
Syntax Highlight
2 parents db3e29b + 56883bf commit d9e6ffc

File tree

3 files changed

+72
-4
lines changed

3 files changed

+72
-4
lines changed

bun.lock

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

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,12 @@
3838
"vite": "^7.1.7"
3939
},
4040
"dependencies": {
41+
"@codemirror/lang-javascript": "^6.2.4",
42+
"@codemirror/theme-one-dark": "^6.1.3",
43+
"@codemirror/view": "^6.38.7",
4144
"@prisma/adapter-pg": "^6.19.0",
4245
"@prisma/client": "^6.19.0",
46+
"svelte-codemirror-editor": "^2.1.0",
4347
"valibot": "^1.1.0"
4448
}
4549
}

src/routes/+page.svelte

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
import { CodeManager } from "$lib/models/CodeManager.svelte";
1010
import BoardModals from "$lib/components/BoardModals.svelte";
1111
import CodeModals from "$lib/components/CodeModals.svelte";
12+
import CodeMirror from "svelte-codemirror-editor";
13+
import { javascript } from "@codemirror/lang-javascript";
14+
import { oneDark } from "@codemirror/theme-one-dark";
15+
import { EditorView } from "@codemirror/view";
1216
1317
let editingCode = $state(lifeGameJS);
1418
let appliedCode = $state(lifeGameJS);
@@ -108,6 +112,20 @@
108112
editingCode = code;
109113
}
110114
}
115+
116+
const editorTheme = EditorView.theme({
117+
"&": {
118+
height: "100%",
119+
maxHeight: "100%",
120+
},
121+
".cm-scroller": {
122+
overflow: "auto",
123+
maxHeight: "100%",
124+
},
125+
".cm-content, .cm-gutter": {
126+
minHeight: "100%",
127+
},
128+
});
111129
</script>
112130

113131
<div class="navbar bg-[#E0E0E0] shadow-sm">
@@ -248,10 +266,14 @@
248266
showEditor ? "basis-[40%] opacity-100" : "basis-0 opacity-0",
249267
]}
250268
>
251-
<textarea
252-
bind:value={editingCode}
253-
class="w-full h-full border-none p-4 font-mono bg-black text-[#0f0]"
254-
></textarea>
269+
<div class="w-full h-full overflow-y-auto">
270+
<CodeMirror
271+
bind:value={editingCode}
272+
lang={javascript()}
273+
theme={oneDark}
274+
extensions={[editorTheme]}
275+
/>
276+
</div>
255277
</div>
256278
</div>
257279

0 commit comments

Comments
 (0)