API getCursorBufferPosition ignoring folded lines


#1

I’m working on a contribution for the package https://atom.io/packages/relative-numbers, I need to find the current buffer’s line taking into account only visible lines (not folded lines). I see the method getCursorBufferPosition returns the line number, however, it returns it taking into account folded lines.

Does anyone knows how to get the current line number ignoring folded lines?


#2

getCursorBufferPosition is designed to ignore folded lines. Note the section in the TextEditor documentation regarding buffer vs. screen coordinates:

Because editors support folds and soft-wrapping, the lines on screen don’t always match the lines in the buffer. For example, a long line that soft wraps twice renders as three lines on screen, but only represents one line in the buffer. Similarly, if rows 5-10 are folded, then row 6 on screen corresponds to row 11 in the buffer.

You’re looking for screen coordinates.


#3

Great. That made me able to work on my contribution (https://github.com/justmoon/relative-numbers/pull/1).

Thanks!