@@ -5,8 +5,6 @@ Debug = require './mixins/debug'
55
66CONFIGS = require ' ./config'
77
8- require ' ../vendor/resizeend'
9-
108module .exports =
119class MinimapView extends View
1210 Debug .includeInto (this )
@@ -81,10 +79,10 @@ class MinimapView extends View
8179
8280 storeActiveEditor : ->
8381 @editorView = @ getEditorView ()
82+ @editor = @editorView .getEditor ()
8483
8584 @ unsubscribeFromEditor ()
8685
87- @editor = @editorView .getEditor ()
8886 @scrollView = @editorView .scrollView
8987 @scrollViewLines = @scrollView .find (' .lines' )
9088
@@ -98,12 +96,19 @@ class MinimapView extends View
9896 @ subscribe @editor , ' scroll-top-changed.minimap' , @updateScroll
9997 # @subscribe @editor, 'scroll-left-changed.minimap', @updateScroll
10098
99+ # See /Applications/Atom.app/Contents/Resources/app/src/pane-view.js#349
100+ # pane-view's private api
101+ # `paneView.activeView` and `paneView.activeItem`
101102 getEditorView : -> @paneView .viewForItem (@activeItem )
102103
103104 getEditorViewClientRect : -> @scrollView [0 ].getBoundingClientRect ()
104105
105106 getScrollViewClientRect : -> @scrollViewLines [0 ].getBoundingClientRect ()
106107
108+ # See https://atom.io/docs/api/v0.83.0/api/classes/Pane.html#getActiveEditor-instance
109+ # Returns an Editor if the pane item is an Editor, or null otherwise.
110+ getEditor : -> @paneView .model .getActiveEditor ()
111+
107112 setMinimapEditorView : ->
108113 # update minimap-editor
109114 setImmediate => @miniEditorView .setEditorView (@editorView )
@@ -116,6 +121,7 @@ class MinimapView extends View
116121 updateMinimapEditorView : => @miniEditorView .update ()
117122
118123 updateMinimapView : =>
124+ return unless @editorView
119125 # offset minimap
120126 @ offset top : @editorView .offset ().top
121127
@@ -154,14 +160,15 @@ class MinimapView extends View
154160
155161 onActiveItemChanged : (item ) =>
156162 # Fix called twice when opening minimap!
157- return if @activeItem == item
163+ return if item is @activeItem
158164 @activeItem = item
159165
160166 if @ activeTabSupportMinimap ()
161167 @ log ' minimap is supported by the current tab'
162168 @ activatePaneViewMinimap () unless @ minimapIsAttached ()
163169 @ storeActiveEditor ()
164170 @ setMinimapEditorView ()
171+ @ updateMinimapView ()
165172 else
166173 # Ignore any tab that is not an editor
167174 @ deactivatePaneViewMinimap ()
@@ -195,12 +202,11 @@ class MinimapView extends View
195202 @isClicked = false
196203 , 377
197204
198- onScrollViewResized : =>
199- @ updateMinimapView ()
205+ onScrollViewResized : => @ updateMinimapView ()
200206
201207 onDragStart : (e ) =>
202208 # only supports for left-click
203- return unless e .which is 1
209+ return if e .which isnt 1
204210 @isPressed = true
205211 @ on ' mousemove.visible-area' , @onMove
206212 @ on ' mouseup.visible-area' , @onDragEnd
@@ -214,10 +220,7 @@ class MinimapView extends View
214220
215221 # OTHER PRIVATE METHODS
216222
217- activeTabSupportMinimap : ->
218- editorView = @ getEditorView ()
219-
220- editorView? and editorView .hasClass (' editor' )
223+ activeTabSupportMinimap : -> @ getEditor ()
221224
222225 scale : (x = 1 ,y = 1 ) -> " scale(#{ x} , #{ y} ) "
223226 translateY : (y = 0 ) -> " translate3d(0, #{ y} px, 0)"
0 commit comments