"virtual" column position


Not sure how to call them correctly, but I mean the column position in a row which respects tabs. Please see the following

Lets assume the same cursor position for all 3 rows. For the first row editor.getCursorBufferPosition().column returns 9, for the second row it returns 7 and for the third row it returns 6. Which is of course ok given my tab width of 4 characters. But this makes it quite hard to compute/position the cursor correctly. Lets assume the cursor position on the first row is after the 6. So my current cursor column is 7. Now in a package I want to set the cursor position to the same vertical column in the next row. editor.setCursorPosition([2,7]) would set the cursor in row 2 after the 8, but I would like to have the cursor after the 5 (or in front of the 8 - doesn’t matter)

Of course I could parse each row before setting the cursor position and compute the (approximately) correct column position, but is there a more convenient way or maybe already an API function? I couldn’t find anything in this scope.



You are probably going to have to calculate it, which should be easy. The only alternative is to go into the DOM and see if there are span elements that have the info you need, which is much harder.


Thanks for your answer. I just thought there could be another way, because I checked some packages working with cursor position and so far all came in troubles when using tabs. I already fixed this for one of my own packages but after I realized that a similar issue came up in my other package, I thought there could be a more central way. Thinking about services … maybe its worth a try to play around and release a package providing a ‘compute-service’. I’ll see.