Getting buffer position from mouse event broken when scrolling…


#1

Hi,

I have done this to get a characterIndex of a mouse event:

pixelPt = pixelPositionFromMouseEvent(@editor, e)
screenPt = @editor.screenPositionForPixelPosition(pixelPt)
bufferPt = @editor.bufferPositionForScreenPosition(screenPt)
textBuffer = @editor.getBuffer()
offset = textBuffer.characterIndexForPosition(bufferPt)

I think this used to work but currently this is broken if I have scrolled down. It works correctly if I’m at the top of the file, but If I scroll down, it doesn’t seem to take into account the scrolling and leaves me with coordinates as if I was at the top.

What am I doing wrong?


#2

Fixed it:

# screen position from mouse event
screenPositionFromMouseEvent = (editor, event) ->
 atom.views.getView(editor).component.screenPositionForMouseEvent event
 # This was broken:
 #editor.screenPositionForPixelPosition(pixelPositionFromMouseEvent(editor, event))

The way I did it before didn’t take the scrolling into account. Pretty sure it has worked a while back though.