Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 885
Ehtesham Ahmad Nadim Avatar asked Sep 17 '25 04:09

Ehtesham Ahmad Nadim


1 Answers

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);
  }
}
like image 129
Ehtesham Ahmad Nadim Avatar answered Sep 18 '25 17:09

Ehtesham Ahmad Nadim