getFirstVisibleScreenRow() in spec tests


I used to have a working test with getFirstVisibleScreenRow().

Currently, when my package’s code runs after being instantiated from the spec test the getFirstVisibleScreenRow() returns 0, as does the corresponding getLastVisibleScreenRow() method.

I have a file loaded with ‘test_text.MD’.

All of the above used to work just fine.

When I enter the debugger in the spec test, I notice that for example:
textEditor.getScreenLineCount() is 34 or textEditor.getLastScreenRow() is 33.

My package’s code of course needs to continue to be focused on the range of rows between the 2 visible points.

code I have is:

        firstVisibleRow = editor.getFirstVisibleScreenRow()
        lastVisibleRow = editor.getLastVisibleScreenRow()

and then later:

        for lineNumber in [firstVisibleRow...lastVisibleRow]

Aside: This time I’m seeing this can probably be:

        for lineNumber in editor.getVisibleRowRange()

So, I think I need a way to set the viewable width/height, basically setting some kind of “screen port” or something. This was something that in the past I left to mystery as it always seemed to work the way I wanted it to, although I always thought that you should have to set it in case you needed to test that kind of thing.


I’ve seen this pattern in a couple Atom packages:

(I just happened to be working on the wrap-guide when this post came in. Serendipitous!)


Heh, that’s awesome, looks great!

Now that I think about it, I should have probably global searched for ‘px’ inside the spec tests :smile:

I’ll let you know how that goes!



Worked like a charm!

BTW, I totally can’t do:

    for lineNumber in editor.getVisibleRowRange()

because that of course doesn’t translate to [0…34] the way my old code did. It’s just [0, 34].

I don’t know the best idiom for this in coffee, there’s probably a nice lodash/underscore for it…or something, basically generate the range from the 2 element array.


You can probably do something like:

range = editor.getVisibleRowRange()
for lineNumber in [range[0]...range[1]]


Yeah, thought of that, but didn’t really like that more than the explicit variables, since range[0] and range[1] don’t really mean much. If coffeescript had tuple expansion I’d do:

firstVisibleRow, lastVisibleRow = editor.getVisibleRowRange()
for lineNumber in [firstVisibleRow…lastVisiblerow]

heh, who cares right!? :smile:


Isn’t this what you are asking for?

[firstVisibleRow, lastVisibleRow] = editor.getVisibleRowRange()
for lineNumber in [firstVisibleRow...lastVisiblerow]


ahh! Thanks @mark_hahn

I tried:

a, b


(a, b)

the [ ] is a little weird there, but who cares. Geez, couldn’t find that on google worth a damn. Now that I think about it, I guess it’s the same construct in coffee how we define global variables etc all over over the place in these packages!