mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 15:05:39 +01:00
Avoid using internals
This commit is contained in:
parent
51fe304f01
commit
ee8392eb0c
2 changed files with 12 additions and 48 deletions
|
|
@ -55,7 +55,9 @@ function getType(type) {
|
|||
|
||||
/** @type {(modifier: string[]|string|null)=>number} */
|
||||
function getModifier(modifiers) {
|
||||
if (typeof modifiers === 'string') modifiers = [modifiers];
|
||||
if (typeof modifiers === 'string') {
|
||||
modifiers = [modifiers];
|
||||
}
|
||||
if (Array.isArray(modifiers)) {
|
||||
let nModifiers = 0;
|
||||
for (let modifier of modifiers) {
|
||||
|
|
@ -91,7 +93,9 @@ monaco.languages.registerDocumentSemanticTokensProvider('plaintext', {
|
|||
for (let match = null; match = tokenPattern.exec(line);) {
|
||||
// translate token and modifiers to number representations
|
||||
let type = getType(match[1]);
|
||||
if (type === -1) continue;
|
||||
if (type === -1) {
|
||||
continue;
|
||||
}
|
||||
let modifier = match[2].length
|
||||
? getModifier(match[2].split('.').slice(1))
|
||||
: 0;
|
||||
|
|
@ -176,29 +180,7 @@ const editor = monaco.editor.create(document.getElementById("container"), {
|
|||
'semanticHighlighting.enabled': true
|
||||
});
|
||||
|
||||
// currently there isn't builtin token handling
|
||||
editor._themeService._knownThemes.forEach(function (theme) {
|
||||
theme.getTokenStyleMetadata = function (type, modifiers) {
|
||||
// use theme rules match
|
||||
const style = theme._tokenTheme._root.match([type].concat(modifiers).join('.'));
|
||||
return {
|
||||
foreground: style._foreground,
|
||||
italic: style._fontStyle & 1,
|
||||
bold: style._fontStyle & 2,
|
||||
underline: style._fontStyle & 4
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
// press F4 to change theme
|
||||
editor.addCommand(monaco.KeyCode.F4, function () {
|
||||
switch (editor._themeService.getTheme().themeName) {
|
||||
case 'vs': monaco.editor.setTheme('vs-dark'); break;
|
||||
case 'vs-dark': monaco.editor.setTheme('hc-black'); break;
|
||||
case 'hc-black': monaco.editor.setTheme('myCustomTheme'); break;
|
||||
case 'myCustomTheme': monaco.editor.setTheme('vs'); break;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/*----------------------------------------SAMPLE JS END*/
|
||||
|
|
|
|||
|
|
@ -18,7 +18,9 @@ function getType(type) {
|
|||
|
||||
/** @type {(modifier: string[]|string|null)=>number} */
|
||||
function getModifier(modifiers) {
|
||||
if (typeof modifiers === 'string') modifiers = [modifiers];
|
||||
if (typeof modifiers === 'string') {
|
||||
modifiers = [modifiers];
|
||||
}
|
||||
if (Array.isArray(modifiers)) {
|
||||
let nModifiers = 0;
|
||||
for (let modifier of modifiers) {
|
||||
|
|
@ -54,7 +56,9 @@ monaco.languages.registerDocumentSemanticTokensProvider('plaintext', {
|
|||
for (let match = null; match = tokenPattern.exec(line);) {
|
||||
// translate token and modifiers to number representations
|
||||
let type = getType(match[1]);
|
||||
if (type === -1) continue;
|
||||
if (type === -1) {
|
||||
continue;
|
||||
}
|
||||
let modifier = match[2].length
|
||||
? getModifier(match[2].split('.').slice(1))
|
||||
: 0;
|
||||
|
|
@ -139,26 +143,4 @@ const editor = monaco.editor.create(document.getElementById("container"), {
|
|||
'semanticHighlighting.enabled': true
|
||||
});
|
||||
|
||||
// currently there isn't builtin token handling
|
||||
editor._themeService._knownThemes.forEach(function (theme) {
|
||||
theme.getTokenStyleMetadata = function (type, modifiers) {
|
||||
// use theme rules match
|
||||
const style = theme._tokenTheme._root.match([type].concat(modifiers).join('.'));
|
||||
return {
|
||||
foreground: style._foreground,
|
||||
italic: style._fontStyle & 1,
|
||||
bold: style._fontStyle & 2,
|
||||
underline: style._fontStyle & 4
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
// press F4 to change theme
|
||||
editor.addCommand(monaco.KeyCode.F4, function () {
|
||||
switch (editor._themeService.getTheme().themeName) {
|
||||
case 'vs': monaco.editor.setTheme('vs-dark'); break;
|
||||
case 'vs-dark': monaco.editor.setTheme('hc-black'); break;
|
||||
case 'hc-black': monaco.editor.setTheme('myCustomTheme'); break;
|
||||
case 'myCustomTheme': monaco.editor.setTheme('vs'); break;
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue