Skip to content

Commit

Permalink
Add model method to compute the visible rows range
Browse files Browse the repository at this point in the history
  • Loading branch information
abe33 committed Dec 12, 2014
1 parent 7aa71b9 commit 5a38ef5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/minimap.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@ class Minimap

getLineHeight: -> @charHeight + @interline

getFirstVisibleRow: ->
Math.floor(@getMinimapScrollTop() / @getLineHeight())

getLastVisibleRow: ->
Math.ceil((@getMinimapScrollTop() + @textEditor.getHeight()) / @getLineHeight())

getMinimapScrollTop: ->
@getTextEditorScrollRatio() * @getMinimapMaxScrollTop()
Math.abs(@getTextEditorScrollRatio() * @getMinimapMaxScrollTop())

getMinimapMaxScrollTop: -> Math.max(0, @getHeight() - @textEditor.getHeight())

Expand Down
8 changes: 7 additions & 1 deletion spec/minimap-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,15 @@ describe 'Minimap', ->
expect(minimap.getMinimapMaxScrollTop()).toEqual(largeLineCount * 5 - 50)
expect(minimap.canScroll()).toBeTruthy()

it 'computes the first visible row in the minimap', ->
expect(minimap.getFirstVisibleRow()).toEqual(0)

it 'computes the last visible row in the minimap', ->
expect(minimap.getLastVisibleRow()).toEqual(10)

describe 'when there is no scrolling needed to display the whole minimap', ->
it 'returns 0 when computing the minimap scroll', ->
expect(minimap.getMinimapScrollTop()).toBeCloseTo(0)
expect(minimap.getMinimapScrollTop()).toEqual(0)

it 'returns 0 when measuring the available minimap scroll', ->
editor.setText(smallSample)
Expand Down

0 comments on commit 5a38ef5

Please sign in to comment.