- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在我目前正在开发的应用程序中使用 Monaco Editor,我需要突出显示编辑器中显示的一些代码行。我目前为此使用 Angular 组件 ngx-monaco-editor (www.npmjs.com/package/ngx-monaco-editor)。
我在摩纳哥游乐场看到了一种使用以下方法做我想做的事情:( https://microsoft.github.io/monaco-editor/playground.html#interacting-with-the-editor-rendering-glyphs-in-the-margin )
var decorations = editor.deltaDecorations([], [
{
range: new monaco.Range(3,1,3,1),
options: {
isWholeLine: true,
className: 'myContentClass',
glyphMarginClassName: 'myGlyphMarginClass'
}
}
]);
editor
对象使用
onInit
事件发射器。我还比较了组件和操场中的对象,它们具有相同的属性,所以我认为它们是相同的。
app.component.html
<ngx-monaco-editor [options]="editorOptions" [(ngModel)]="code" (onInit)="onInit($event)"></ngx-monaco-editor>
app.component.ts
editorOptions = {
theme: 'vs',
language: 'javascript',
glyphMargin: true
};
code = [
'"use strict";',
'function Person(age) {',
' if (age) {',
' this.age = age;',
' }',
'}',
'Person.prototype.getAge = function () {',
' return this.age;',
'};'
].join('\n');
onInit(editor: any) {
const t = editor.deltaDecorations([], [
{
range: new monaco.Range(3, 1, 3, 1),
options: {
isWholeLine: true,
className: 'myContentClass',
glyphMarginClassName: 'myGlyphMarginClass'
}
}
]);
console.log(t);
}
app.component.css
.myGlyphMarginClass {
background: red;
}
.myContentClass {
background: lightblue;
}
最佳答案
问题实际上来自这样一个事实,即 monaco 不查找您的特定组件样式表,而是查找您应用程序的全局样式表。
标签设置正确,但由于根样式页面中没有对类样式的引用,因此没有任何更改或显示。
为了解决这个问题,你需要在你的根样式文件中添加你的类并且它可以工作。
祝你今天过得愉快 :)
关于angular - 摩纳哥 deltaDecorations 不适用于 angular 7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56770919/
我正在使用带有 React 的 Monaco 编辑器.我想更改一行中特定范围的背景颜色。我正在关注 this tutorial这是来自官方文档。 代码如下所示。 const editorDidMoun
我正在尝试在我目前正在开发的应用程序中使用 Monaco Editor,我需要突出显示编辑器中显示的一些代码行。我目前为此使用 Angular 组件 ngx-monaco-editor (www.np
文档说它已被弃用: (方法) editor.ICodeEditor.deltaDecorations(oldDecorations: string[], newDecorations: monaco.
我是一名优秀的程序员,十分优秀!