javascript - How to add, remove and change glyphs in Monaco Editor - Stack Overflow

I am able to add glyph to the editor but I am not able to remove and edit the glyph. Can you please giv

I am able to add glyph to the editor but I am not able to remove and edit the glyph. Can you please give me the right way of doing it.

<h2>Monaco Editor Sample</h2>
<div id="container" style="width:80%;height:600px;border:1px solid grey"></div>

<!-- OR ANY OTHER AMD LOADER HERE INSTEAD OF loader.js -->
<script src="../node_modules/monaco-editor/min/vs/loader.js"></script>
<script>
    var editor,decorations;
    require.config({ paths: { 'vs': '../node_modules/monaco-editor/min/vs' }});
    require(['vs/editor/editor.main'], function() {
         editor = monaco.editor.create(document.getElementById('container'), {
            value: [
                'function x() {',
                '\tconsole.log("Hello world!");',
                '}',
            ].join('\n'),
            language: 'javascript',
            theme: "myCustomTheme",
            automaticLayout: true,
            readOnly: false,
            mouseWheelZoom:true,
            glyphMargin:true,
            fontSize:'20px'
        });
   //below is the glyph I am calling
    var decorations = editor.deltaDecorations([], [     
    {
        range: new monaco.Range(3,1,3,1),
        options: {
            isWholeLine: true,
            className: 'myContentClass',
            glyphMarginClassName: 'glyph-error',
        }
    }
    ]);
    });
</script>

I am trying to delete or modify the range and style of the glyph using decorations variable but it is a string object.

This is the how my editor looks with a squared glyph:

I am able to add glyph to the editor but I am not able to remove and edit the glyph. Can you please give me the right way of doing it.

<h2>Monaco Editor Sample</h2>
<div id="container" style="width:80%;height:600px;border:1px solid grey"></div>

<!-- OR ANY OTHER AMD LOADER HERE INSTEAD OF loader.js -->
<script src="../node_modules/monaco-editor/min/vs/loader.js"></script>
<script>
    var editor,decorations;
    require.config({ paths: { 'vs': '../node_modules/monaco-editor/min/vs' }});
    require(['vs/editor/editor.main'], function() {
         editor = monaco.editor.create(document.getElementById('container'), {
            value: [
                'function x() {',
                '\tconsole.log("Hello world!");',
                '}',
            ].join('\n'),
            language: 'javascript',
            theme: "myCustomTheme",
            automaticLayout: true,
            readOnly: false,
            mouseWheelZoom:true,
            glyphMargin:true,
            fontSize:'20px'
        });
   //below is the glyph I am calling
    var decorations = editor.deltaDecorations([], [     
    {
        range: new monaco.Range(3,1,3,1),
        options: {
            isWholeLine: true,
            className: 'myContentClass',
            glyphMarginClassName: 'glyph-error',
        }
    }
    ]);
    });
</script>

I am trying to delete or modify the range and style of the glyph using decorations variable but it is a string object.

This is the how my editor looks with a squared glyph:

Share Improve this question edited May 13, 2021 at 16:13 Sabuncu 5,2846 gold badges59 silver badges95 bronze badges asked Apr 8, 2020 at 12:05 yogendra maarisettyyogendra maarisetty 3803 silver badges16 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

The return value of deltaDecorations is an array of strings. Each string is an identifier of a decoration that was created by the last deltaDecorations call.

To modify an existing decoration you must replace it with a new one as shown below.

var decorations = editor.deltaDecorations([], [     
    {
        range: new monaco.Range(3,1,3,1),
        options: {
            isWholeLine: true,
            className: 'myContentClass',
            glyphMarginClassName: 'glyph-error',
        }
    }
]);

// Now move the previously created decoration to line 2
var targetId = decorations[0];
editor.deltaDecorations([targetId], [     
    {
        range: new monaco.Range(2,1,2,1),
        options: {
            isWholeLine: true,
            className: 'myContentClass',
            glyphMarginClassName: 'glyph-error',
        }
    }
]);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745047728a4608197.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信