diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index 71793e3ec..fbe514f73 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -2225,21 +2225,44 @@ describe "Editor", -> runs -> expect(editor.getText()).toBe(originalPathText) - describe "when clicking a gutter line", -> + describe "when clicking in the gutter", -> beforeEach -> - rootView.attachToDom() + editor.attachToDom() - it "moves the cursor to the start of the selected line", -> - expect(editor.getCursorScreenPosition()).toEqual [0,0] - editor.gutter.find(".line-number:eq(1)").trigger 'click' - expect(editor.getCursorScreenPosition()).toEqual [1,0] + describe "when single clicking", -> + it "moves the cursor to the start of the selected line", -> + expect(editor.getCursorScreenPosition()).toEqual [0,0] + event = $.Event("mousedown") + event.pageY = editor.gutter.find(".line-number:eq(1)").offset().top + event.originalEvent = {detail: 1} + editor.gutter.find(".line-number:eq(1)").trigger event + 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]] - event = $.Event("click") - event.shiftKey = true - editor.gutter.find(".line-number:eq(1)").trigger event - expect(editor.getSelection().getScreenRange()).toEqual [[0,0], [1,0]] + describe "when shift-clicking", -> + it "selects to the start of the selected line", -> + expect(editor.getSelection().getScreenRange()).toEqual [[0,0], [0,0]] + event = $.Event("mousedown") + event.pageY = editor.gutter.find(".line-number:eq(1)").offset().top + event.originalEvent = {detail: 1} + event.shiftKey = true + editor.gutter.find(".line-number:eq(1)").trigger event + expect(editor.getSelection().getScreenRange()).toEqual [[0,0], [1,0]] + + describe "when mousing down and then moving across multiple lines before mousing up", -> + it "selects the lines", -> + mousedownEvent = $.Event("mousedown") + mousedownEvent.pageY = editor.gutter.find(".line-number:eq(1)").offset().top + mousedownEvent.originalEvent = {detail: 1} + editor.gutter.find(".line-number:eq(1)").trigger mousedownEvent + + mousemoveEvent = $.Event("mousemove") + mousemoveEvent.pageY = editor.gutter.find(".line-number:eq(5)").offset().top + mousemoveEvent.originalEvent = {detail: 1} + editor.gutter.find(".line-number:eq(5)").trigger mousemoveEvent + + $(document).trigger 'mouseup' + + expect(editor.getSelection().getScreenRange()).toEqual [[1,0], [5,30]] describe "when clicking below the last line", -> beforeEach -> diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 56d89b97d..842539291 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -385,7 +385,7 @@ class Editor extends View @destroyFold($(e.currentTarget).attr('fold-id')) false - @renderedLines.on 'mousedown', (e) => + onMouseDown = (e) => clickCount = e.originalEvent.detail screenPosition = @screenPositionFromMouseEvent(e) @@ -403,6 +403,8 @@ class Editor extends View @selectOnMousemoveUntilMouseup() + @renderedLines.on 'mousedown', onMouseDown + @on "textInput", (e) => @insertText(e.originalEvent.data) false @@ -419,6 +421,10 @@ class Editor extends View @gutter.widthChanged = (newWidth) => @scrollView.css('left', newWidth + 'px') + @gutter.on 'mousedown', (e) => + e.pageX = @renderedLines.offset().left + onMouseDown(e) + @subscribe syntax, 'grammars-loaded', => @reloadGrammar() for session in @editSessions diff --git a/src/app/gutter.coffee b/src/app/gutter.coffee index 9f7de8f7a..b541595b2 100644 --- a/src/app/gutter.coffee +++ b/src/app/gutter.coffee @@ -23,13 +23,6 @@ class Gutter extends View highlightLines = => @highlightLines() editor.on 'cursor:moved', highlightLines editor.on 'selection:changed', 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()