From 216e98140d80c92bfc31ca83cb5cec47863b0db1 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 13 Aug 2015 12:30:28 -0600 Subject: [PATCH 1/2] Eliminate unused argument --- src/text-editor-component.coffee | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/text-editor-component.coffee b/src/text-editor-component.coffee index 8d3bfc579..a2ed0ff8d 100644 --- a/src/text-editor-component.coffee +++ b/src/text-editor-component.coffee @@ -403,7 +403,7 @@ class TextEditorComponent when 3 @editor.getLastSelection().selectLine() - @handleDragUntilMouseUp event, (screenPosition) => + @handleDragUntilMouseUp (screenPosition) => @editor.selectToScreenPosition(screenPosition, true) onLineNumberGutterMouseDown: (event) => @@ -424,7 +424,7 @@ class TextEditorComponent @editor.setSelectedBufferRange([[clickedBufferRow, 0], [clickedBufferRow + 1, 0]], preserveFolds: true) - @handleDragUntilMouseUp event, (screenPosition) => + @handleDragUntilMouseUp (screenPosition) => dragRow = screenPosition.row dragBufferRow = @editor.bufferRowForScreenRow(dragRow) if dragBufferRow < clickedBufferRow # dragging up @@ -440,7 +440,7 @@ class TextEditorComponent bufferRange = new Range([clickedBufferRow, 0], [clickedBufferRow + 1, 0]) rowSelection = @editor.addSelectionForBufferRange(bufferRange, preserveFolds: true) - @handleDragUntilMouseUp event, (screenPosition) => + @handleDragUntilMouseUp (screenPosition) => dragRow = screenPosition.row dragBufferRow = @editor.bufferRowForScreenRow(dragRow) @@ -466,7 +466,7 @@ class TextEditorComponent else @editor.selectToBufferPosition([clickedBufferRow + 1, 0]) - @handleDragUntilMouseUp event, (screenPosition) => + @handleDragUntilMouseUp (screenPosition) => dragRow = screenPosition.row dragBufferRow = @editor.bufferRowForScreenRow(dragRow) if dragRow < tailPosition.row # dragging up @@ -523,7 +523,7 @@ class TextEditorComponent onCursorMoved: => @cursorMoved = true - handleDragUntilMouseUp: (event, dragHandler) => + handleDragUntilMouseUp: (dragHandler) => dragging = false lastMousePosition = {} animationLoop = => From a88b648144c179d3baa0a4958b0af3c35bf864d5 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 13 Aug 2015 12:53:02 -0600 Subject: [PATCH 2/2] Unify gutter drag logic This ensures the same approach is used to drag the gutter for all modes of selection. --- src/text-editor-component.coffee | 65 ++++++++++---------------------- 1 file changed, 20 insertions(+), 45 deletions(-) diff --git a/src/text-editor-component.coffee b/src/text-editor-component.coffee index a2ed0ff8d..a46b352a3 100644 --- a/src/text-editor-component.coffee +++ b/src/text-editor-component.coffee @@ -419,61 +419,36 @@ class TextEditorComponent @onGutterClick(event) onGutterClick: (event) => - clickedRow = @screenPositionForMouseEvent(event).row - clickedBufferRow = @editor.bufferRowForScreenRow(clickedRow) - + clickedBufferRow = @editor.bufferRowForScreenRow(@screenPositionForMouseEvent(event).row) @editor.setSelectedBufferRange([[clickedBufferRow, 0], [clickedBufferRow + 1, 0]], preserveFolds: true) - - @handleDragUntilMouseUp (screenPosition) => - dragRow = screenPosition.row - dragBufferRow = @editor.bufferRowForScreenRow(dragRow) - if dragBufferRow < clickedBufferRow # dragging up - @editor.setSelectedBufferRange([[dragBufferRow, 0], [clickedBufferRow + 1, 0]], reversed: true, preserveFolds: true, autoscroll: false) - else - @editor.setSelectedBufferRange([[clickedBufferRow, 0], [dragBufferRow + 1, 0]], reversed: false, preserveFolds: true, autoscroll: false) - @editor.getLastCursor().autoscroll() + @handleGutterDrag(clickedBufferRow) onGutterMetaClick: (event) => - clickedRow = @screenPositionForMouseEvent(event).row - clickedBufferRow = @editor.bufferRowForScreenRow(clickedRow) - - bufferRange = new Range([clickedBufferRow, 0], [clickedBufferRow + 1, 0]) - rowSelection = @editor.addSelectionForBufferRange(bufferRange, preserveFolds: true) - - @handleDragUntilMouseUp (screenPosition) => - dragRow = screenPosition.row - dragBufferRow = @editor.bufferRowForScreenRow(dragRow) - - if dragBufferRow < clickedBufferRow # dragging up - rowSelection.setBufferRange([[dragBufferRow, 0], [clickedBufferRow + 1, 0]], preserveFolds: true) - else - rowSelection.setBufferRange([[clickedBufferRow, 0], [dragBufferRow + 1, 0]], preserveFolds: true) - - # The merge process will possibly destroy the current selection because - # it will be merged into another one. Therefore, we need to obtain a - # reference to the new selection that contains the originally selected row - rowSelection = _.find @editor.getSelections(), (selection) -> - selection.intersectsBufferRange(bufferRange) + clickedBufferRow = @editor.bufferRowForScreenRow(@screenPositionForMouseEvent(event).row) + @editor.addSelectionForBufferRange([[clickedBufferRow, 0], [clickedBufferRow + 1, 0]], preserveFolds: true) + @handleGutterDrag(clickedBufferRow) onGutterShiftClick: (event) => - clickedRow = @screenPositionForMouseEvent(event).row - clickedBufferRow = @editor.bufferRowForScreenRow(clickedRow) - tailPosition = @editor.getLastSelection().getTailScreenPosition() - tailBufferPosition = @editor.bufferPositionForScreenPosition(tailPosition) + clickedBufferRow = @editor.bufferRowForScreenRow(@screenPositionForMouseEvent(event).row) + tailBufferPosition = @editor.getLastSelection().getTailBufferPosition() - if clickedRow < tailPosition.row - @editor.selectToBufferPosition([clickedBufferRow, 0]) + if clickedBufferRow < tailBufferPosition.row + @editor.selectToBufferPosition([clickedBufferRow, 0], true) else - @editor.selectToBufferPosition([clickedBufferRow + 1, 0]) + @editor.selectToBufferPosition([clickedBufferRow + 1, 0], true) + + @handleGutterDrag(tailBufferPosition.row, tailBufferPosition.column) + + handleGutterDrag: (tailRow, tailColumn) -> + tailPosition = [tailRow, tailColumn] if tailColumn? @handleDragUntilMouseUp (screenPosition) => - dragRow = screenPosition.row - dragBufferRow = @editor.bufferRowForScreenRow(dragRow) - if dragRow < tailPosition.row # dragging up - @editor.setSelectedBufferRange([[dragBufferRow, 0], tailBufferPosition], preserveFolds: true) + dragRow = @editor.bufferPositionForScreenPosition(screenPosition).row + if dragRow < tailRow + @editor.getLastSelection().setBufferRange([[dragRow, 0], tailPosition ? [tailRow + 1, 0]], reversed: true, autoscroll: false, preserveFolds: true) else - @editor.setSelectedBufferRange([tailBufferPosition, [dragBufferRow + 1, 0]], preserveFolds: true) - + @editor.getLastSelection().setBufferRange([tailPosition ? [tailRow, 0], [dragRow + 1, 0]], reversed: false, autoscroll: false, preserveFolds: true) + @editor.getLastCursor().autoscroll() onStylesheetsChanged: (styleElement) => return unless @performedInitialMeasurement