From 5a38ef5c87d98ba02186714b8dfa8f047b9bb016 Mon Sep 17 00:00:00 2001 From: abe33 Date: Fri, 12 Dec 2014 16:49:45 +0100 Subject: [PATCH] Add model method to compute the visible rows range --- lib/minimap.coffee | 8 +++++++- spec/minimap-spec.coffee | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/minimap.coffee b/lib/minimap.coffee index 2ca3bba0..f84fa60b 100644 --- a/lib/minimap.coffee +++ b/lib/minimap.coffee @@ -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()) diff --git a/spec/minimap-spec.coffee b/spec/minimap-spec.coffee index e605c518..818db87d 100644 --- a/spec/minimap-spec.coffee +++ b/spec/minimap-spec.coffee @@ -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)