Search code examples
ace-editor

How to work with ace multiple cursors?


I have an ace editor for a project and I want to make colorful cursors which appear under some conditions.

While coding these cursors should be static (the user cannot move them).

How I can add a cursor and fill it with some color?


Solution

  • What you're after are called Markers.

    This will set a background marker behind some text on line 0, column 6 through 10:

    var Range = ace.require('ace/range').Range;
    var range = new Range(0, 6, 0, 10);
    var marker = editor.session.addMarker(range, 'ace_myclass', 'text');
    

    To remove it:

    editor.session.removeMarker(marker);
    

    See:

    http://ace.c9.io/#nav=api&api=edit_session