From 2e517425bc086003f8c1fa94aa410764639fd99e Mon Sep 17 00:00:00 2001 From: abe33 Date: Fri, 12 Dec 2014 15:47:59 +0100 Subject: [PATCH] Add more scroll related methods --- lib/minimap.coffee | 4 ++++ spec/minimap-spec.coffee | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/minimap.coffee b/lib/minimap.coffee index 2abe557c..a0098aa4 100644 --- a/lib/minimap.coffee +++ b/lib/minimap.coffee @@ -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) => diff --git a/spec/minimap-spec.coffee b/spec/minimap-spec.coffee index f2f98c64..4c61f363 100644 --- a/spec/minimap-spec.coffee +++ b/spec/minimap-spec.coffee @@ -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()