Skip to content

Commit

Permalink
Add option to move the cursor when clicking to scroll in the minimap
Browse files Browse the repository at this point in the history
Closes #515
  • Loading branch information
abe33 committed Sep 1, 2016
1 parent 7931505 commit 73f84fc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/minimap-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,10 @@ export default class MinimapElement {
const scrollTop = row * textEditor.getLineHeightInPixels() - this.minimap.getTextEditorHeight() / 2
const textEditorScrollTop = textEditorElement.pixelPositionForScreenPosition([row, 0]).top - this.minimap.getTextEditorHeight() / 2

if (atom.config.get('minimap.moveCursorOnMinimapClick')) {
textEditor.setCursorScreenPosition([row, 0])
}

if (atom.config.get('minimap.scrollAnimation')) {
const duration = atom.config.get('minimap.scrollAnimationDuration')
const independentScroll = this.minimap.scrollIndependentlyOnMouseWheel()
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@
"default":300,
"description":"The duration of scrolling animations when clicking on the minimap."
},
"moveCursorOnMinimapClick": {
"type": "boolean",
"default": false,
"description": "Moves the cursor to the beginning of the target line when clicking on the minimap"
},
"smoothScrolling": {
"type": "boolean",
"default": true,
Expand Down
11 changes: 11 additions & 0 deletions spec/minimap-element-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,17 @@ describe('MinimapElement', () => {
expect(editorElement.getScrollTop()).toBeCloseTo(480)
})
})

describe('when moveCursorOnMinimapClick is true', () => {
beforeEach(() => {
atom.config.set('minimap.moveCursorOnMinimapClick', true)
})

it('moves the cursor to the corresponding line', () => {
mousedown(canvas)
expect(editor.getCursorScreenPosition()).toEqual([40, 0])
})
})
})

describe('pressing the mouse on the minimap canvas (with scroll animation)', () => {
Expand Down

0 comments on commit 73f84fc

Please sign in to comment.