Caret position getSelectionEndPosition returns wrong value on soft wrap

Hi,
Calling caret.getSelectionEndPosition().getLine() for lines wrapped by soft wrap return wrong values. In my case, a very long document consisting of two lines is soft wrapped. The caret position will return 31 afterwards - which is utterly wrong.
Is there any other API function I can use to get the correct line or is this a bug?

Tested with IU-141.498.1 on both Ubuntu 14.04 and Windows 7 (on multiple computers).
Also referenced in https://intellij-support.jetbrains.com/requests/58008

Thanks,
Matthias

2 comments
Comment actions Permalink

Hi Matthias,

SelectionModel.getSelectionEndPosition() returns a VisualPosition, so it's entirely correct that the position takes soft wrapping into account. You can use Editor.visualToLogicalPosition() to convert it to a logical position which will contain the actual line number in the document.

0
Comment actions Permalink

Hi Dimitry,

thanks this works :-)

Matthias

0

Please sign in to leave a comment.