Skip to content

Commit f969e3b

Browse files
committed
Add split-view demo, styles
1 parent e72299c commit f969e3b

4 files changed

Lines changed: 74 additions & 18 deletions

File tree

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ A CodeMirror extension that provides C# syntax highlighting and language support
88
```ts
99
import { EditorState } from '@codemirror/state';
1010
import { EditorView } from '@codemirror/view';
11-
import { csharp } from "@replit/codemirror-lang-csharp";
11+
import { csharp } from '@replit/codemirror-lang-csharp';
1212
import { basicSetup } from 'codemirror';
1313

1414
new EditorView({
@@ -17,13 +17,13 @@ new EditorView({
1717
using System;
1818
namespace Test
1919
{
20-
class Program
21-
{
22-
public static void Main(string[] args)
20+
class Program
2321
{
24-
Console.WriteLine("Hello, world!");
22+
public static void Main(string[] args)
23+
{
24+
Console.WriteLine("Hello, world!");
25+
}
2526
}
26-
}
2727
}
2828
`,
2929
extensions: [basicSetup, csharp()],

dev/index.css

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
:root {
2+
color-scheme: dark;
3+
}
4+
5+
body,
6+
html {
7+
width: 100%;
8+
height: 100%;
9+
}
10+
11+
body {
12+
margin: 0;
13+
overflow: hidden;
14+
}
15+
16+
div.split-view {
17+
width: 100%;
18+
height: 100%;
19+
display: flex;
20+
gap: 0.3rem;
21+
}
22+
23+
div.split-view #editor,
24+
div.split-view #syntax {
25+
display: flex;
26+
width: 50%;
27+
overflow: auto;
28+
}
29+
30+
div.split-view #editor .cm-editor,
31+
div.split-view #syntax pre {
32+
flex: 1;
33+
outline: none;
34+
overflow: inherit;
35+
}
36+
37+
div.split-view #syntax pre {
38+
margin: 0;
39+
padding: 4px 2px 4px 6px;
40+
}
41+
42+
@media (max-width: 767px) {
43+
div.split-view {
44+
flex-direction: column;
45+
}
46+
47+
div.split-view #editor,
48+
div.split-view #syntax {
49+
width: 100%;
50+
height: 50%;
51+
}
52+
}

dev/index.html

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44
<head>
55
<meta charset="UTF-8" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7-
<title>Vite App</title>
8-
<style>
9-
:root {
10-
color-scheme: dark;
11-
}
12-
</style>
7+
<title>codemirror-lang-csharp</title>
8+
<meta name="description" content="A C# mode for CodeMirror 6">
9+
<link rel="icon" href="https://avatars.githubusercontent.com/u/983194">
10+
<link rel="stylesheet" href="./index.css" />
11+
<script type="module" src="./index.ts"></script>
1312
</head>
1413

15-
<body class="replit-ui-theme-root dark">
16-
<div id="editor"></div>
17-
<script type="module" src="./index.ts"></script>
14+
<body>
15+
<div class="split-view">
16+
<div id="editor"></div>
17+
<div id="syntax"></div>
18+
</div>
1819
</body>
1920

2021
</html>

dev/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ namespace osu.Game.Rulesets
233233
}
234234
`
235235

236+
const syntax = document.createElement('pre');
237+
syntax.className = 'ͼo';
238+
document.getElementById('syntax')!.appendChild(syntax);
239+
236240
new EditorView({
237241
state: EditorState.create({
238242
doc,
@@ -242,15 +246,14 @@ new EditorView({
242246
oneDark,
243247
keymap.of([indentWithTab]),
244248
indentUnit.of(' '),
245-
EditorView.lineWrapping,
246249
EditorView.updateListener.of(e => {
247250
if (e.docChanged) {
248251
const doc = e.state.doc.toString();
249-
console.log(printTree(parser.parse(doc), doc));
252+
syntax.textContent = printTree(parser.parse(doc), doc);
250253
}
251254
})],
252255
}),
253256
parent: document.querySelector('#editor')!,
254257
});
255258

256-
console.log(printTree(parser.parse(doc), doc));
259+
syntax.textContent = printTree(parser.parse(doc), doc);

0 commit comments

Comments
 (0)