reactjslatexhighlightace-editorreact-ace

How to remove all the existing highlight markers in ace editor using react


I am using ace editor and I am highlighting lines by defining this code:

var Range = ace.require('ace/range').Range;
editor.session.addMarker(new Range(item - 1, 0, item - 1, 1), "warning-marker", "fullLine");

Now I want to remove all the markers that I have used in my editor considering I don't have any marker id.


Solution

  • This is how I solved the issue finally:

    const prevMarkers = editor.session.getMarkers();
    if (prevMarkers) {
      const prevMarkersArr = Object.keys(prevMarkers);
      for (let item of prevMarkersArr) {
        editor.session.removeMarker(prevMarkers[item].id);
      }
    }