Skip to content

Commit

Permalink
Add more scroll related methods
Browse files Browse the repository at this point in the history
  • Loading branch information
abe33 committed Dec 12, 2014
1 parent 481a39e commit 2e51742
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/minimap.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class Minimap

getLineHeight: -> @charHeight + @interline

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

canScroll: -> @getMinimapScrollHeight() > 0

subscribeToConfig: ->
@subscriptions.add atom.config.observe 'minimap.charHeight', (@charHeight) =>
@subscriptions.add atom.config.observe 'minimap.charWidth', (@charWidth) =>
Expand Down
15 changes: 15 additions & 0 deletions spec/minimap-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,18 @@ describe 'Minimap', ->
editor.setScrollTop(1000)

expect(minimap.getTextEditorScroll()).toEqual(500)

it 'measures the available minimap scroll', ->
editor.setText(largeSample)
largeLineCount = editor.getLineCount()

expect(minimap.getMinimapScrollHeight()).toEqual(largeLineCount * 5 - 50)
expect(minimap.canScroll()).toBeTruthy()

describe 'when there is no scrolling needed to display the whole minimap', ->
describe 'measuring the available minimap scroll', ->
it 'returns 0', ->
editor.setText(smallSample)

expect(minimap.getMinimapScrollHeight()).toEqual(0)
expect(minimap.canScroll()).toBeFalsy()

0 comments on commit 2e51742

Please sign in to comment.