Support clicking line numbers in gutter

Clicking moves the cursor to the start of the
row and shift-clicking selects to the start of
the row
This commit is contained in:
Kevin Sawicki
2012-12-22 23:40:23 -08:00
parent b59bd7a099
commit ff3b04e01e
2 changed files with 21 additions and 0 deletions

View File

@@ -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]

View File

@@ -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: ->