Skip to content

Commit 95bc0a0

Browse files
authored
fix: aysnc language sytax colorization (#124)
1 parent c649e51 commit 95bc0a0

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@coze-editor/extensions",
5+
"comment": "aysnc language sytax colorization",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@coze-editor/extensions",
10+
"email": "hanchayi@163.com"
11+
}

packages/text-editor/extensions/src/brackets/colorization.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
type ViewUpdate,
99
type DecorationSet,
1010
} from '@codemirror/view';
11-
import { syntaxTree } from '@codemirror/language';
11+
import { syntaxTree, language } from '@codemirror/language';
1212

1313
const DEFAULT_COLORS = ['#ffd700', '#da70d6', '#179fff'];
1414

@@ -21,12 +21,21 @@ const ColorizationBracketsPlugin = ViewPlugin.fromClass(
2121
}
2222

2323
update(update: ViewUpdate) {
24-
if (update.docChanged || update.selectionSet || update.viewportChanged) {
24+
if (
25+
update.docChanged ||
26+
update.selectionSet ||
27+
update.viewportChanged ||
28+
update.state.facet(language) !== update.startState.facet(language)
29+
) {
2530
this.decorations = this.getBracketDecorations(update.view);
2631
}
2732
}
2833

2934
getBracketDecorations(view: EditorView) {
35+
if (!view.state.facet(language)) {
36+
return Decoration.none;
37+
}
38+
3039
const { doc } = view.state;
3140
const decorations: any[] = [];
3241
const stack: { type: string; from: number }[] = [];

0 commit comments

Comments
 (0)