Skip to content

Commit

Permalink
🐛 Fix minimap model not relying on screen lines
Browse files Browse the repository at this point in the history
  • Loading branch information
abe33 committed Dec 16, 2014
1 parent da7fd15 commit 3ea02bf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/minimap.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Minimap extends Model
getTextEditorScrollRatio: ->
@textEditor.getScrollTop() / @textEditor.displayBuffer.getMaxScrollTop()

getHeight: -> @textEditor.getLineCount() * @getLineHeight()
getHeight: -> @textEditor.getScreenLineCount() * @getLineHeight()

getVerticalScaleFactor: ->
@getLineHeight() / @textEditor.getLineHeightInPixels()
Expand Down Expand Up @@ -79,7 +79,7 @@ class Minimap extends Model
canScroll: -> @getMinimapMaxScrollTop() > 0

getMarker: (id) -> @textEditor.getMarker(id)

findMarkers: (o) -> @textEditor.findMarkers(o)

markBufferRange: (range) -> @textEditor.markBufferRange(range)
Expand Down
21 changes: 17 additions & 4 deletions spec/minimap-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ describe 'Minimap', ->

it 'measures the minimap size based on the current editor content', ->
editor.setText(smallSample)
expect(minimap.getHeight()).toEqual(20)
expect(minimap.getHeight()).toEqual(editor.getScreenLineCount() * 5)

editor.setText(largeSample)
expect(minimap.getHeight()).toEqual(editor.getLineCount() * 5)
expect(minimap.getHeight()).toEqual(editor.getScreenLineCount() * 5)

it 'measures the scaling factor between the editor and the minimap', ->
expect(minimap.getVerticalScaleFactor()).toEqual(0.5)
Expand All @@ -42,7 +42,7 @@ describe 'Minimap', ->

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

expect(minimap.getMinimapMaxScrollTop()).toEqual(largeLineCount * 5 - 50)
expect(minimap.canScroll()).toBeTruthy()
Expand Down Expand Up @@ -81,6 +81,19 @@ describe 'Minimap', ->

expect(scrollSpy).toHaveBeenCalled()

describe 'when soft wrap is enabled', ->
beforeEach ->
atom.config.set 'editor.softWrap', true
atom.config.set 'editor.softWrapAtPreferredLineLength', true
atom.config.set 'editor.preferredLineLength', 2

it 'measures the minimap using screen lines', ->
editor.setText(smallSample)
expect(minimap.getHeight()).toEqual(editor.getScreenLineCount() * 5)

editor.setText(largeSample)
expect(minimap.getHeight()).toEqual(editor.getScreenLineCount() * 5)

describe 'when there is no scrolling needed to display the whole minimap', ->
it 'returns 0 when computing the minimap scroll', ->
expect(minimap.getMinimapScrollTop()).toEqual(0)
Expand All @@ -99,7 +112,7 @@ describe 'Minimap', ->
editor.setScrollTop(1000)
editor.setScrollLeft(200)

largeLineCount = editor.getLineCount()
largeLineCount = editor.getScreenLineCount()
editorHeight = largeLineCount * editor.getLineHeightInPixels()
editorScrollRatio = editor.getScrollTop() / editor.displayBuffer.getMaxScrollTop()

Expand Down

0 comments on commit 3ea02bf

Please sign in to comment.