How do you determine if cursor is off-screen?


#1

I haven’t been able to figure out a way to do this yet from the API docs - how do you determine if a cursor is off-screen? Comparing screen and buffer coordinates doesn’t work because screen coordinates aren’t relative to the viewport.


#2

What do you mean by screen?


#3

Out of the viewport (ie. not visible)


#4

So you mean the browser window? Maybe this?

$(window).mouseleave ->


#5

Oops sorry, I mean an instance of Atom’s Cursor.


#6

No, my problem. I’m too literal-minded.

Aren’t there first-visible-line and last-visible line functions? I seem to remember using them. I’ll check my code.


#7

Maybe this? (untested)

    editorEle = atom.views.getView editor
    topRow = editorEle.getFirstVisibleScreenRow() 
    botRow = editorEle.getLastVisibleScreenRow()
    curRow = editor.getCursorBufferPosition().row
    visible =  (topRow <= curRow <= botRow)

Edit: I just checked and getFirstVisibleScreenRow is not in the API. It works in my code though. Hopefully they haven’t deprecated it.