Skip to content

Commit 0db4d71

Browse files
committed
simple drag-to-scroll
1 parent 07adaf7 commit 0db4d71

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

lib/minimap-view.coffee

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ class MinimapView extends View
3434
@minimapScroll = 0
3535

3636
initialize: ->
37+
38+
isPressed = false
39+
@on 'mousedown', '.minimap-visible-area', (e) =>
40+
isPressed = true
41+
@on 'mousemove.visible-area', (e) =>
42+
if isPressed
43+
@.triggerHandler 'mousedown', e
44+
@on 'mouseup.visible-area', (e) =>
45+
isPressed = false
46+
@off '.visible-area'
47+
3748
@on 'mousewheel', @onMouseWheel
3849
@on 'mousedown', @onMouseDown
3950

@@ -170,14 +181,16 @@ class MinimapView extends View
170181
if wheelDeltaY
171182
@editorView.scrollTop(@editorView.scrollTop() - wheelDeltaY)
172183

173-
onMouseDown: (e) =>
184+
onMouseDown: (e, te) =>
174185
@isClicked = true
175186
e.preventDefault()
176187
e.stopPropagation()
177188
minimapHeight = @miniScrollView.outerHeight()
178189
miniVisibleAreaHeight = @miniVisibleArea.height()
190+
# `te` is a extraParameter of triggerHandler
191+
pageY = e.pageY || (te && te.pageY)
179192
# Overlayer's center-y
180-
y = e.pageY - @offset().top
193+
y = pageY - @offset().top
181194
y = y - @minimapScroll * @scaleY
182195
n = y / @scaleY
183196
top = n - miniVisibleAreaHeight / 2

0 commit comments

Comments
 (0)