Fetch uncommented line number from monaco editor

78 views Asked by At

I am working in monaco editor. I need to fetch a line number and I understand that the below line is used to fetch the line number from the editor.

editor.getPosition().lineNumber

But in some scenarios my editor would contain commented lines as well , so when I fetch the lines I need to exclude the commented lines and get only the uncommented line number. Is there any method to do so?

example:

//Line1:

//Line2:

//Line3:

//Line4:

//Line5:

Line1: -- current cursor position is here

Line2:

Above is my scenario. First 5 lines in my editor are commented. If my cursor is present in the uncommented Line1 and when I use "editor.getPosition().lineNumber" it gives 6 as the result . In this case I need 1 as the result.

I need to make this changes in jquery

1

There are 1 answers

0
Mike Lischke On

Monaco cannot give you a different line number, as it always uses the entire text is has. If you need to figure out a specific position within the text, you have to parse it and get the position from a specific element you are interested in.