How to get all markers on a Editor?


I’m creating a simple extension that marks (or highlights) the current selection, like the “markSelection” addon from v5.
Most of the extension code is taken from this example: CodeMirror 5 to 6 Migration Guide.

The extension works correctly, and I am able to mark / unmark different parts of the code.
Now, I want to be able to know all the parts that are currently marked in the Editor (ranges information would be enough).

The idea is that I have a “Save” button somewhere in my page, that will send the current code to my API, but I also want to send the information of what is marked. This way, when I reload the page, I get those markers too, and I am able to redisplay the markers to the user.

I must say that I am a bit lost with all the new features of v6, and I am not sure what would be the better way to do that.

Thanks a lot.


An extension like the one in the migration guide keeps a range set of markers in a state field. You can do state.field(theFieldObject) to get its content, and use the between method on it to iterate over all markers in a given range.

Thanks @marijn that’s indeed helpful!