Skip to content

Commit dc79245

Browse files
authored
feat(monaco): normalize theme tokenScopes and tighten monaco type import (#1140)
1 parent fb05a9e commit dc79245

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

packages/monaco/src/index.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ShikiInternal, ThemeRegistrationResolved } from '@shikijs/types'
2-
import type monacoNs from 'monaco-editor-core'
2+
import type * as monacoNs from 'monaco-editor-core'
33
import type { MonacoLineToken } from './types'
44
import { EncodedTokenMetadata, INITIAL } from '@shikijs/vscode-textmate'
55
import { TokenizerState } from './tokenizer'
@@ -32,18 +32,16 @@ export function textmateThemeToMonacoTheme(theme: ThemeRegistrationResolved): Mo
3232
const themeSettings = theme.settings || theme.tokenColors
3333

3434
for (const { scope, settings: { foreground, background, fontStyle } = {} } of themeSettings) {
35-
const scopes = Array.isArray(scope) ? scope : [scope]
36-
37-
for (const s of scopes) {
38-
if (s && (foreground || background || fontStyle)) {
39-
rules.push({
40-
token: s,
41-
foreground: normalizeColor(foreground),
42-
background: normalizeColor(background),
43-
fontStyle,
44-
})
45-
}
46-
}
35+
if (!foreground && !background && !fontStyle)
36+
continue
37+
const scopes = Array.isArray(scope) ? scope : scope ? [scope] : []
38+
39+
rules.push(...scopes.map(s => ({
40+
token: s,
41+
foreground: normalizeColor(foreground),
42+
background: normalizeColor(background),
43+
fontStyle,
44+
})))
4745
}
4846
}
4947

0 commit comments

Comments
 (0)