Skip to content

Commit e72299c

Browse files
committed
Enable dark scheme; add tab indent & live parse
1 parent 0b018ce commit e72299c

4 files changed

Lines changed: 34 additions & 19 deletions

File tree

dev/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
<meta charset="UTF-8" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<title>Vite App</title>
8+
<style>
9+
:root {
10+
color-scheme: dark;
11+
}
12+
</style>
813
</head>
914

1015
<body class="replit-ui-theme-root dark">

dev/index.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { EditorState } from '@codemirror/state';
2-
import { EditorView } from '@codemirror/view';
2+
import { EditorView, keymap } from '@codemirror/view';
33
import { basicSetup } from 'codemirror';
44
import { indentUnit } from '@codemirror/language';
5+
import { indentWithTab } from '@codemirror/commands';
56
import { csharp, parser } from '../dist/';
67
import { printTree } from './print-lezer-tree';
78
import { oneDark } from '@codemirror/theme-one-dark';
89

9-
const doc = /*`
10-
using System;
10+
const doc = /*`using System;
1111
using System.Reflection;
1212
1313
public sealed class InterrogateHelpUrls
@@ -28,8 +28,7 @@ public sealed class InterrogateHelpUrls
2828
}
2929
}
3030
}
31-
`*/`
32-
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
31+
`*/`// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
3332
// See the LICENCE file in the repository root for full licence text.
3433
3534
using System;
@@ -235,11 +234,23 @@ namespace osu.Game.Rulesets
235234
`
236235

237236
new EditorView({
238-
state: EditorState.create({
239-
doc,
240-
extensions: [basicSetup, csharp(), oneDark, indentUnit.of(' '), EditorView.lineWrapping],
241-
}),
242-
parent: document.querySelector('#editor')!,
237+
state: EditorState.create({
238+
doc,
239+
extensions: [
240+
basicSetup,
241+
csharp(),
242+
oneDark,
243+
keymap.of([indentWithTab]),
244+
indentUnit.of(' '),
245+
EditorView.lineWrapping,
246+
EditorView.updateListener.of(e => {
247+
if (e.docChanged) {
248+
const doc = e.state.doc.toString();
249+
console.log(printTree(parser.parse(doc), doc));
250+
}
251+
})],
252+
}),
253+
parent: document.querySelector('#editor')!,
243254
});
244255

245256
console.log(printTree(parser.parse(doc), doc));

src/index.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ export const csharpLanguage = LRLanguage.define({
1515
parser: parser.configure({
1616
props: [
1717
indentNodeProp.add({
18-
Delim: continuedIndent({ except: /^\s*(?:case\b|default:)/ }),
18+
Delim: continuedIndent({ except: /^\s*(?:case\b|default:)/ })
1919
}),
2020
foldNodeProp.add({
21-
Delim: foldInside,
21+
Delim: foldInside
2222
}),
2323
styleTags({
2424
"Keyword ContextualKeyword SimpleType": t.keyword,
@@ -47,16 +47,15 @@ export const csharpLanguage = LRLanguage.define({
4747

4848
"( )": t.paren,
4949
"{ }": t.brace,
50-
"[ ]": t.squareBracket,
51-
}),
52-
],
50+
"[ ]": t.squareBracket
51+
})
52+
]
5353
}),
5454
languageData: {
5555
commentTokens: { line: "//", block: { open: "/*", close: "*/" } },
5656
closeBrackets: { brackets: ["(", "[", "{", '"', "'"] },
57-
indentOnInput:
58-
/^\s*((\)|\]|\})$|(else|else\s+if|catch|finally|case)\b|default:)/,
59-
},
57+
indentOnInput: /^\s*((\)|\]|\})$|(else|else\s+if|catch|finally|case)\b|default:)/
58+
}
6059
});
6160

6261
export function csharp() {

src/tokens.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
interpStringEnd,
66
interpVStringContent,
77
interpVStringBrace,
8-
interpVStringEnd,
8+
interpVStringEnd
99
} from "./syntax.grammar.terms";
1010

1111
const

0 commit comments

Comments
 (0)