diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index 8d61188e2..1ee20fa91 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -1990,3 +1990,15 @@ describe "Editor", -> runs -> expect(editor.getText()).toBe(originalPathText) + + describe "when clicking a gutter line", -> + it "moves the cursor to the start of the selected line", -> + rootView.attachToDom() + expect(editor.getCursorScreenPosition()).toEqual [0,0] + editor.gutter.find(".line-number:eq(1)").trigger 'click' + expect(editor.getCursorScreenPosition()).toEqual [1,0] + + it "selects to the start of the selected line when shift is pressed", -> + expect(editor.getSelection().getScreenRange()).toEqual [0,0], [0,0] + editor.gutter.find(".line-number:eq(1)").trigger 'click', {shiftKey: true} + expect(editor.getSelection().getScreenRange()).toEqual [0,0], [1,0] diff --git a/src/app/gutter.coffee b/src/app/gutter.coffee index 93e1ae61e..19e63708b 100644 --- a/src/app/gutter.coffee +++ b/src/app/gutter.coffee @@ -3,6 +3,7 @@ $ = require 'jquery' _ = require 'underscore' Range = require 'range' +Point = require 'point' module.exports = class Gutter extends View @@ -22,6 +23,14 @@ class Gutter extends View highlightLines = => @highlightLines() editor.on 'cursor-move', highlightLines editor.on 'selection-change', highlightLines + @on 'click', '.line-number', (e) => + row = parseInt($(e.target).text()) - 1 + position = new Point(row, 0) + if e.shiftKey + @editor().selectToScreenPosition(position) + else + @editor().setCursorScreenPosition(position) + @calculateWidth() editor: ->