How to get the character that is on the cursor position?



I’m trying to write a plugin and I need to get the character that is at the cursor position. I can get the cursor position with editor.getCursor().getBufferPosition(), which returns a Point(). I assume I can use this point to get text from the screen with editor.getTextInRange() or editor.getTextInBufferRange(), but I just can’t figure exactly how.

The docs say these methods expect a Range(). I tried creating a range with new Range([1, 2], [1, 5]) and pass that as an argument to the .getTextInRange() and .getTextInBufferRange() functions, but they always return an empty string.

Can anyone shed some light over this?



Scratch that, I found a way to do it, here’s how if someone else needs to do that:

  cursor.getBufferPosition().add([0, 1])


There’s also: