From d1dec4e0cf392e34be797489318e240888dd9517 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 28 Jul 2015 16:16:34 -0600 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20autoscroll=20to=20selection=20w?= =?UTF-8?q?hen=20double-=20or=20triple-click=20dragging?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/text-editor-component-spec.coffee | 52 ++++++++++++++++++++++++++ src/selection.coffee | 6 ++- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/spec/text-editor-component-spec.coffee b/spec/text-editor-component-spec.coffee index 48e5eddd5..5e272a566 100644 --- a/spec/text-editor-component-spec.coffee +++ b/spec/text-editor-component-spec.coffee @@ -1807,6 +1807,58 @@ describe "TextEditorComponent", -> expect(window.removeEventListener).toHaveBeenCalledWith('mouseup') expect(window.removeEventListener).toHaveBeenCalledWith('mousemove') + describe "when the mouse is double-clicked and dragged", -> + it "expands the selection over the nearest word as the cursor moves", -> + jasmine.attachToDOM(wrapperNode) + wrapperNode.style.height = 6 * lineHeightInPixels + 'px' + component.measureDimensions() + nextAnimationFrame() + + linesNode.dispatchEvent(buildMouseEvent('mousedown', clientCoordinatesForScreenPosition([5, 10]), detail: 1)) + linesNode.dispatchEvent(buildMouseEvent('mouseup')) + linesNode.dispatchEvent(buildMouseEvent('mousedown', clientCoordinatesForScreenPosition([5, 10]), detail: 2)) + expect(editor.getSelectedScreenRange()).toEqual [[5, 6], [5, 13]] + + linesNode.dispatchEvent(buildMouseEvent('mousemove', clientCoordinatesForScreenPosition([11, 11]), which: 1)) + nextAnimationFrame() + expect(editor.getSelectedScreenRange()).toEqual [[5, 6], [11, 13]] + + maximalScrollTop = editor.getScrollTop() + + linesNode.dispatchEvent(buildMouseEvent('mousemove', clientCoordinatesForScreenPosition([9, 3]), which: 1)) + nextAnimationFrame() + expect(editor.getSelectedScreenRange()).toEqual [[5, 6], [9, 4]] + expect(editor.getScrollTop()).toBe maximalScrollTop # does not autoscroll upward (regression) + + linesNode.dispatchEvent(buildMouseEvent('mouseup', clientCoordinatesForScreenPosition([9, 3]), which: 1)) + + describe "when the mouse is triple-clicked and dragged", -> + it "expands the selection over the nearest line as the cursor moves", -> + jasmine.attachToDOM(wrapperNode) + wrapperNode.style.height = 6 * lineHeightInPixels + 'px' + component.measureDimensions() + nextAnimationFrame() + + linesNode.dispatchEvent(buildMouseEvent('mousedown', clientCoordinatesForScreenPosition([5, 10]), detail: 1)) + linesNode.dispatchEvent(buildMouseEvent('mouseup')) + linesNode.dispatchEvent(buildMouseEvent('mousedown', clientCoordinatesForScreenPosition([5, 10]), detail: 2)) + linesNode.dispatchEvent(buildMouseEvent('mouseup')) + linesNode.dispatchEvent(buildMouseEvent('mousedown', clientCoordinatesForScreenPosition([5, 10]), detail: 3)) + expect(editor.getSelectedScreenRange()).toEqual [[5, 0], [6, 0]] + + linesNode.dispatchEvent(buildMouseEvent('mousemove', clientCoordinatesForScreenPosition([11, 11]), which: 1)) + nextAnimationFrame() + expect(editor.getSelectedScreenRange()).toEqual [[5, 0], [12, 0]] + + maximalScrollTop = editor.getScrollTop() + + linesNode.dispatchEvent(buildMouseEvent('mousemove', clientCoordinatesForScreenPosition([8, 4]), which: 1)) + nextAnimationFrame() + expect(editor.getSelectedScreenRange()).toEqual [[5, 0], [9, 0]] + expect(editor.getScrollTop()).toBe maximalScrollTop # does not autoscroll upward (regression) + + linesNode.dispatchEvent(buildMouseEvent('mouseup', clientCoordinatesForScreenPosition([9, 3]), which: 1)) + describe "when a line is folded", -> beforeEach -> editor.foldBufferRow 4 diff --git a/src/selection.coffee b/src/selection.coffee index b7b7bb2fb..043c88548 100644 --- a/src/selection.coffee +++ b/src/selection.coffee @@ -324,7 +324,8 @@ class Selection extends Model # Public: Expands the newest selection to include the entire word on which # the cursors rests. expandOverWord: -> - @setBufferRange(@getBufferRange().union(@cursor.getCurrentWordBufferRange())) + @setBufferRange(@getBufferRange().union(@cursor.getCurrentWordBufferRange()), autoscroll: false) + @cursor.autoscroll() # Public: Selects an entire line in the buffer. # @@ -342,7 +343,8 @@ class Selection extends Model # It also includes the newline character. expandOverLine: -> range = @getBufferRange().union(@cursor.getCurrentLineBufferRange(includeNewline: true)) - @setBufferRange(range) + @setBufferRange(range, autoscroll: false) + @cursor.autoscroll() ### Section: Modifying the selected text