From 518a71910d467f7cd3caa6ffa69072d178f6b25a Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 26 Dec 2012 11:04:10 -0800 Subject: [PATCH] Support clicking past last editor line Clicking below the last line of an editor now either moves the cursor to the end of the file or selects to the end of the file if shift is pressed. --- spec/app/editor-spec.coffee | 19 +++++++++++++++++++ src/app/editor.coffee | 8 ++++++++ 2 files changed, 27 insertions(+) diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index 08fb14cd4..a04731bc5 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -2006,3 +2006,22 @@ describe "Editor", -> event.shiftKey = true editor.gutter.find(".line-number:eq(1)").trigger event expect(editor.getSelection().getScreenRange()).toEqual [[0,0], [1,0]] + + describe "when clicking below the last line", -> + beforeEach -> + rootView.attachToDom() + + it "move the cursor to the end of the file", -> + expect(editor.getCursorScreenPosition()).toEqual [0,0] + event = $.Event("click") + event.offsetY = Infinity + editor.scrollView.trigger event + expect(editor.getCursorScreenPosition()).toEqual [12,2] + + it "selects to the end of the files when shift is pressed", -> + expect(editor.getSelection().getScreenRange()).toEqual [[0,0], [0,0]] + event = $.Event("click") + event.offsetY = Infinity + event.shiftKey = true + editor.scrollView.trigger event + expect(editor.getSelection().getScreenRange()).toEqual [[0,0], [12,2]] diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 774a3142a..4e9e97cb0 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -326,6 +326,14 @@ class Editor extends View @removeClass 'focused' @autosave() if config.get "editor.autosave" + @scrollView.on 'click', (e) => + return unless e.target is @scrollView[0] + return unless e.offsetY > @overlayer.height() + if e.shiftKey + @selectToBottom() + else + @moveCursorToBottom() + @overlayer.on 'mousedown', (e) => @overlayer.hide() clickedElement = document.elementFromPoint(e.pageX, e.pageY)