@@ -7,6 +7,9 @@ class MinimapView extends View
77 @CONFIGS = {
88 }
99
10+ @minTop : 0
11+ @maxTop : 0
12+
1013 @ content: ->
1114 @ div class : ' minimap' , =>
1215 @ div outlet : ' miniOverlayer' , class : " minimap-overlayer"
@@ -20,6 +23,9 @@ class MinimapView extends View
2023 @ subscribe atom .workspaceView , ' cursor:moved' , =>
2124 @ update ()
2225
26+ this .off (' mousewheel' )
27+ this .on (' mousewheel' , @mousewheelFn .bind (this ))
28+
2329 attach : ->
2430
2531 destroy : ->
@@ -64,40 +70,118 @@ class MinimapView extends View
6470 if this .hasClass (' hide' )
6571 this .removeClass (' hide' )
6672
73+ @editor .off (' scroll-top-changed.editor' )
74+ @editor .on (' scroll-top-changed.editor' , @scroll .bind (this ))
75+
6776 top = @editorView .offset ().top
6877 this .css (' top' , top + ' px' )
6978
7079 @ reset ()
7180
7281 @miniEditorView .update (@editor .getText (), @editor .displayBuffer .screenLines )
7382
74- editorRect = @scrollView [0 ].getBoundingClientRect ()
83+ @ editorRect = @scrollView [0 ].getBoundingClientRect ()
7584 linesRect = @scrollView .find (' .lines' )[0 ].getBoundingClientRect ()
7685 miniRect = @miniEditorView .getClientRect ()
7786
87+ @minTop = 0
88+ @maxTop = @miniEditorView .height ()
89+
90+ @miniEditorView .find (' .scroll-view' ).css ({
91+ top : 0
92+ })
93+
94+ # height of editor
95+ a = @editorRect .height / miniRect .height
96+ # 180 height
97+ @miniOverlayer .css ({
98+ height : miniRect .height * a,
99+ top : 0
100+ })
101+
102+ height = miniRect .height
78103 width = Math .max (150 , miniRect .width )
79104
80- if linesRect .height < editorRect .height
81- scaleX = 0.2
82- width = 150 / scaleX
105+ if linesRect .height < @ editorRect .height
106+ @ scaleX = 0.2
107+ width = 150 / @ scaleX
83108 else
84- scaleX = 150 / miniRect .width
109+ @ scaleX = 150 / miniRect .width
85110
86- scaleY = scaleX
87- scaleStr = ' scale(' + scaleX + ' , ' + scaleY + ' )'
111+ @scaleX = Math .max (@scaleX , 0.1 )
112+
113+ x = width - 150 / @scaleX
114+ y = 0
115+
116+ # --- test
117+ # @scaleX = .3
118+ # @scaleY = .3
119+ # --- test
120+ @scaleY = @scaleX
121+ scaleStr = ' scale(' + @scaleX + ' , ' + @scaleY + ' )'
122+ translateStr = ' translate(' + x + ' px, ' + y + ' px)'
88123 this .css ({
89124 width : width,
90- ' -webkit-transform' : scaleStr,
91- ' transform' : scaleStr
125+ ' -webkit-transform' : scaleStr + ' ' + translateStr ,
126+ ' transform' : scaleStr + ' ' + translateStr
92127 })
93128
129+ @ scroll (@editorView .scrollTop ())
130+
94131 reset : ->
95132 scaleX = 1
96133 scaleY = scaleX
97134 scaleStr = ' scale(' + scaleX + ' , ' + scaleY + ' )'
135+ translateStr = ' translate(0, 0)'
98136
99137 this .css ({
100138 width : 150 ,
101- ' -webkit-transform' : scaleStr,
102- ' transform' : scaleStr
139+ ' -webkit-transform' : scaleStr + ' ' + translateStr ,
140+ ' transform' : scaleStr + ' ' + translateStr
103141 })
142+
143+ mousewheelFn : (e ) ->
144+ delta = e .originalEvent .wheelDeltaY
145+ if delta
146+ @editorView .scrollTop (@editorView .scrollTop () - delta)
147+
148+ # h = @miniEditorView.height() * @scaleX
149+
150+ # if h > @scrollView.height()
151+ # t = parseInt(@miniEditorView.find('.scroll-view').css('top'))
152+ # t += delta
153+ # t = Math.min(t, 0)
154+ # #t = Math.max(Math.min(t, @maxTop - @miniOverlayer.height()), @minTop)
155+ # @miniEditorView.find('.scroll-view').css({
156+ # top: t
157+ # })
158+ # #n = parseInt(@miniOverlayer.css('top'))
159+ # #n -= delta
160+ # #n = Math.max(Math.min(n, t + ), @minTop)
161+ # @miniOverlayer.css({
162+ # top: n
163+ # })
164+ # else
165+ # t = parseInt(@miniOverlayer.css('top'))
166+ # t -= delta
167+ # t = Math.max(Math.min(t, @maxTop - @miniOverlayer.height()), @minTop)
168+ # @miniOverlayer.css({
169+ # top: t
170+ # })
171+
172+ scroll : (top ) ->
173+ h = @miniEditorView .height () * @scaleX
174+
175+ if h > @scrollView .height ()
176+ n = (top) / (@editorView .find (' .lines' ).outerHeight () - @editorView .height ())
177+ sv = @miniEditorView .find (' .scroll-view' )
178+ sv .css ({
179+ top : - (sv .outerHeight () - @miniOverlayer .height () / @scaleX ) * n
180+ })
181+ @miniOverlayer .css ({
182+ top : n * (@miniOverlayer .height () / @scaleX - @miniOverlayer .height ())
183+ })
184+ else
185+ @miniOverlayer .css ({
186+ top : top
187+ })
0 commit comments