I'm using Ace for a collaborative editing experience and I want to be able to scroll to another user's cursor position.
I see that there are editor.scrollToRow()
, and editor.scrollToLine()
methods, but I can't seem to find any method that works with a cursor
object that has position
and selectionEnd
properties.
What I'd like is to be able to scroll to a position, not just a line. Or if there is a way to convert a position to a line that would be helpful too.
Thanks!
Position is an object like {row, column} so getting a line from it is easy by using position.row.
You can also use
editor.renderer.scrollCursorIntoView({row: 50, column: 1}, 0.5)
(0.5 centers the line on screen use 1 for bottom 0 for top)
I guess I'm on an older version where the position is just the character position, but that will be nice when I can upgrade.
Must be something else, that code didn't change much from the very beginning.
If you have chracter index in value string editor.session.doc.indexToPosition(index)
can help you to get {row, column}
but that is a relatively slow function.
Thanks for the response! You're right about the Ace cursor API. I now think it has to do with my Firepad plugin doing something else weird with it, so there's nothing wrong on the Ace side.
Most helpful comment
Position is an object like {row, column} so getting a line from it is easy by using position.row.
You can also use
editor.renderer.scrollCursorIntoView({row: 50, column: 1}, 0.5)
(0.5 centers the line on screen use 1 for bottom 0 for top)