Skip to content

Commit

Permalink
🐛 Fix getTextEditorScrollRatio() return NaN, #260
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon committed Feb 10, 2015
1 parent ebd2509 commit 2d65659
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/minimap.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ class Minimap
#
# Returns a {Number}.
getTextEditorScrollRatio: ->
@textEditor.getScrollTop() / @getTextEditorMaxScrollTop()
# Because `0/0 = NaN`, so make sure that the denominator does not equal `0`.
@textEditor.getScrollTop() / (@getTextEditorMaxScrollTop() || 1)

# Returns the `TextEditor` scroll as a value normalized between `0` and `1`.
#
Expand Down
14 changes: 14 additions & 0 deletions spec/minimap-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,20 @@ describe 'Minimap', ->
editor.setScrollTop(editor.displayBuffer.getMaxScrollTop())
expect(minimap.getScrollTop()).toEqual(minimap.getMaxScrollTop())

describe 'when getScrollTop() and maxScrollTop both equal 0', ->
beforeEach ->
editor.setText(smallSample)
editor.setHeight(40)
atom.config.set 'editor.scrollPastEnd', true

it 'getTextEditorScrollRatio() should return 0', ->
editor.setScrollTop(0)

maxScrollTop = editor.displayBuffer.getMaxScrollTop() - (editor.getHeight() - 3 * editor.displayBuffer.getLineHeightInPixels())

expect(maxScrollTop).toEqual(0)
expect(minimap.getTextEditorScrollRatio()).toEqual(0)

describe 'when soft wrap is enabled', ->
beforeEach ->
atom.config.set 'editor.softWrap', true
Expand Down

1 comment on commit 2d65659

@abe33
Copy link
Contributor

@abe33 abe33 commented on 2d65659 Feb 10, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Great catch!

Please sign in to comment.