diff --git a/spec/text-editor-component-spec.coffee b/spec/text-editor-component-spec.coffee index 9f8d5dfec..0ecc08ac2 100644 --- a/spec/text-editor-component-spec.coffee +++ b/spec/text-editor-component-spec.coffee @@ -2133,99 +2133,99 @@ describe "TextEditorComponent", -> expect(editor.getSelectedScreenRange()).toEqual [[0, 0], [7, 4]] describe "when the clicked row is after the current selection's tail", -> - it "selects to the beginning of the buffer row following the clicked buffer row", -> + it "selects to the beginning of the screen row following the clicked buffer row", -> gutterNode.dispatchEvent(buildMouseEvent('mousedown', clientCoordinatesForScreenRowInGutter(11), shiftKey: true)) expect(editor.getSelectedScreenRange()).toEqual [[7, 4], [16, 0]] describe "when the gutter is clicked and dragged", -> describe "when dragging downward", -> - it "selects the buffer rows between the start and end of the drag", -> + it "selects the buffer row containing the click, then screen rows until the end of the drag", -> gutterNode.dispatchEvent(buildMouseEvent('mousedown', clientCoordinatesForScreenRowInGutter(1))) gutterNode.dispatchEvent(buildMouseEvent('mousemove', clientCoordinatesForScreenRowInGutter(6))) nextAnimationFrame() gutterNode.dispatchEvent(buildMouseEvent('mouseup', clientCoordinatesForScreenRowInGutter(6))) - expect(editor.getSelectedScreenRange()).toEqual [[0, 0], [10, 0]] + expect(editor.getSelectedScreenRange()).toEqual [[0, 0], [6, 14]] describe "when dragging upward", -> - it "selects the buffer rows between the start and end of the drag", -> + it "selects the buffer row containing the click, then screen rows until the end of the drag", -> gutterNode.dispatchEvent(buildMouseEvent('mousedown', clientCoordinatesForScreenRowInGutter(6))) gutterNode.dispatchEvent(buildMouseEvent('mousemove', clientCoordinatesForScreenRowInGutter(1))) nextAnimationFrame() gutterNode.dispatchEvent(buildMouseEvent('mouseup', clientCoordinatesForScreenRowInGutter(1))) - expect(editor.getSelectedScreenRange()).toEqual [[0, 0], [10, 0]] + expect(editor.getSelectedScreenRange()).toEqual [[1, 0], [10, 0]] describe "when the gutter is meta-clicked and dragged", -> beforeEach -> editor.setSelectedScreenRange([[7, 4], [7, 6]]) describe "when dragging downward", -> - it "selects the buffer rows between the start and end of the drag", -> + it "adds a selection from the buffer row containing the click to the screen row containing the end of the drag", -> gutterNode.dispatchEvent(buildMouseEvent('mousedown', clientCoordinatesForScreenRowInGutter(1), metaKey: true)) gutterNode.dispatchEvent(buildMouseEvent('mousemove', clientCoordinatesForScreenRowInGutter(3), metaKey: true)) nextAnimationFrame() gutterNode.dispatchEvent(buildMouseEvent('mouseup', clientCoordinatesForScreenRowInGutter(3), metaKey: true)) - expect(editor.getSelectedScreenRanges()).toEqual [[[7, 4], [7, 6]], [[0, 0], [5, 0]]] + expect(editor.getSelectedScreenRanges()).toEqual [[[7, 4], [7, 6]], [[0, 0], [3, 14]]] - it "merges overlapping selections", -> + it "merges overlapping selections on mouseup", -> gutterNode.dispatchEvent(buildMouseEvent('mousedown', clientCoordinatesForScreenRowInGutter(1), metaKey: true)) gutterNode.dispatchEvent(buildMouseEvent('mousemove', clientCoordinatesForScreenRowInGutter(7), metaKey: true)) nextAnimationFrame() gutterNode.dispatchEvent(buildMouseEvent('mouseup', clientCoordinatesForScreenRowInGutter(7), metaKey: true)) - expect(editor.getSelectedScreenRanges()).toEqual [[[0, 0], [10, 0]]] + expect(editor.getSelectedScreenRanges()).toEqual [[[0, 0], [7, 12]]] describe "when dragging upward", -> - it "selects the buffer rows between the start and end of the drag", -> + it "adds a selection from the buffer row containing the click to the screen row containing the end of the drag", -> gutterNode.dispatchEvent(buildMouseEvent('mousedown', clientCoordinatesForScreenRowInGutter(17), metaKey: true)) gutterNode.dispatchEvent(buildMouseEvent('mousemove', clientCoordinatesForScreenRowInGutter(11), metaKey: true)) nextAnimationFrame() gutterNode.dispatchEvent(buildMouseEvent('mouseup', clientCoordinatesForScreenRowInGutter(11), metaKey: true)) - expect(editor.getSelectedScreenRanges()).toEqual [[[7, 4], [7, 6]], [[10, 0], [19, 0]]] + expect(editor.getSelectedScreenRanges()).toEqual [[[7, 4], [7, 6]], [[11, 4], [19, 0]]] - it "merges overlapping selections", -> + it "merges overlapping selections on mouseup", -> gutterNode.dispatchEvent(buildMouseEvent('mousedown', clientCoordinatesForScreenRowInGutter(17), metaKey: true)) - gutterNode.dispatchEvent(buildMouseEvent('mousemove', clientCoordinatesForScreenRowInGutter(9), metaKey: true)) + gutterNode.dispatchEvent(buildMouseEvent('mousemove', clientCoordinatesForScreenRowInGutter(5), metaKey: true)) nextAnimationFrame() - gutterNode.dispatchEvent(buildMouseEvent('mouseup', clientCoordinatesForScreenRowInGutter(9), metaKey: true)) + gutterNode.dispatchEvent(buildMouseEvent('mouseup', clientCoordinatesForScreenRowInGutter(5), metaKey: true)) expect(editor.getSelectedScreenRanges()).toEqual [[[5, 0], [19, 0]]] describe "when the gutter is shift-clicked and dragged", -> describe "when the shift-click is below the existing selection's tail", -> describe "when dragging downward", -> - it "selects the buffer rows between the existing selection's tail and the end of the drag", -> + it "selects the screen rows between the existing selection's tail and the end of the drag", -> editor.setSelectedScreenRange([[1, 4], [1, 7]]) gutterNode.dispatchEvent(buildMouseEvent('mousedown', clientCoordinatesForScreenRowInGutter(7), shiftKey: true)) gutterNode.dispatchEvent(buildMouseEvent('mousemove', clientCoordinatesForScreenRowInGutter(11))) nextAnimationFrame() - expect(editor.getSelectedScreenRange()).toEqual [[1, 4], [16, 0]] + expect(editor.getSelectedScreenRange()).toEqual [[1, 4], [11, 14]] describe "when dragging upward", -> - it "selects the buffer rows between the end of the drag and the tail of the existing selection", -> + it "selects the screen rows between the end of the drag and the tail of the existing selection", -> editor.setSelectedScreenRange([[1, 4], [1, 7]]) gutterNode.dispatchEvent(buildMouseEvent('mousedown', clientCoordinatesForScreenRowInGutter(11), shiftKey: true)) gutterNode.dispatchEvent(buildMouseEvent('mousemove', clientCoordinatesForScreenRowInGutter(7))) nextAnimationFrame() - expect(editor.getSelectedScreenRange()).toEqual [[1, 4], [10, 0]] + expect(editor.getSelectedScreenRange()).toEqual [[1, 4], [7, 12]] describe "when the shift-click is above the existing selection's tail", -> describe "when dragging upward", -> - it "selects the buffer rows between the end of the drag and the tail of the existing selection", -> + it "selects the screen rows between the end of the drag and the tail of the existing selection", -> editor.setSelectedScreenRange([[7, 4], [7, 6]]) gutterNode.dispatchEvent(buildMouseEvent('mousedown', clientCoordinatesForScreenRowInGutter(3), shiftKey: true)) gutterNode.dispatchEvent(buildMouseEvent('mousemove', clientCoordinatesForScreenRowInGutter(1))) nextAnimationFrame() - expect(editor.getSelectedScreenRange()).toEqual [[0, 0], [7, 4]] + expect(editor.getSelectedScreenRange()).toEqual [[1, 0], [7, 4]] describe "when dragging downward", -> - it "selects the buffer rows between the existing selection's tail and the end of the drag", -> + it "selects the screen rows between the existing selection's tail and the end of the drag", -> editor.setSelectedScreenRange([[7, 4], [7, 6]]) gutterNode.dispatchEvent(buildMouseEvent('mousedown', clientCoordinatesForScreenRowInGutter(1), shiftKey: true)) gutterNode.dispatchEvent(buildMouseEvent('mousemove', clientCoordinatesForScreenRowInGutter(3))) nextAnimationFrame() - expect(editor.getSelectedScreenRange()).toEqual [[2, 0], [7, 4]] + expect(editor.getSelectedScreenRange()).toEqual [[3, 2], [7, 4]] describe "focus handling", -> inputNode = null @@ -3225,7 +3225,7 @@ describe "TextEditorComponent", -> {clientX, clientY} clientCoordinatesForScreenRowInGutter = (screenRow) -> - positionOffset = wrapperNode.pixelPositionForScreenPosition([screenRow, 1]) + positionOffset = wrapperNode.pixelPositionForScreenPosition([screenRow, Infinity]) gutterClientRect = componentNode.querySelector('.gutter').getBoundingClientRect() clientX = gutterClientRect.left + positionOffset.left - editor.getScrollLeft() clientY = gutterClientRect.top + positionOffset.top - editor.getScrollTop() diff --git a/src/text-editor-component.coffee b/src/text-editor-component.coffee index af0b71f3b..b058378b8 100644 --- a/src/text-editor-component.coffee +++ b/src/text-editor-component.coffee @@ -419,35 +419,43 @@ class TextEditorComponent @onGutterClick(event) onGutterClick: (event) => - clickedBufferRow = @editor.bufferRowForScreenRow(@screenPositionForMouseEvent(event).row) - @editor.setSelectedBufferRange([[clickedBufferRow, 0], [clickedBufferRow + 1, 0]], preserveFolds: true) - @handleGutterDrag(clickedBufferRow) + clickedScreenRow = @screenPositionForMouseEvent(event).row + clickedBufferRow = @editor.bufferRowForScreenRow(clickedScreenRow) + initialScreenRange = @editor.screenRangeForBufferRange([[clickedBufferRow, 0], [clickedBufferRow + 1, 0]]) + @editor.setSelectedScreenRange(initialScreenRange, preserveFolds: true) + @handleGutterDrag(initialScreenRange) onGutterMetaClick: (event) => - clickedBufferRow = @editor.bufferRowForScreenRow(@screenPositionForMouseEvent(event).row) - @editor.addSelectionForBufferRange([[clickedBufferRow, 0], [clickedBufferRow + 1, 0]], preserveFolds: true) - @handleGutterDrag(clickedBufferRow) + clickedScreenRow = @screenPositionForMouseEvent(event).row + clickedBufferRow = @editor.bufferRowForScreenRow(clickedScreenRow) + initialScreenRange = @editor.screenRangeForBufferRange([[clickedBufferRow, 0], [clickedBufferRow + 1, 0]]) + @editor.addSelectionForScreenRange(initialScreenRange, preserveFolds: true) + @handleGutterDrag(initialScreenRange) onGutterShiftClick: (event) => - clickedBufferRow = @editor.bufferRowForScreenRow(@screenPositionForMouseEvent(event).row) - tailBufferPosition = @editor.getLastSelection().getTailBufferPosition() + tailScreenPosition = @editor.getLastSelection().getTailScreenPosition() + clickedScreenRow = @screenPositionForMouseEvent(event).row + clickedBufferRow = @editor.bufferRowForScreenRow(clickedScreenRow) + clickedLineScreenRange = @editor.screenRangeForBufferRange([[clickedBufferRow, 0], [clickedBufferRow + 1, 0]]) - if clickedBufferRow < tailBufferPosition.row - @editor.selectToBufferPosition([clickedBufferRow, 0], true) + if clickedScreenRow < tailScreenPosition.row + @editor.selectToScreenPosition(clickedLineScreenRange.start, true) else - @editor.selectToBufferPosition([clickedBufferRow + 1, 0], true) + @editor.selectToScreenPosition(clickedLineScreenRange.end, true) - @handleGutterDrag(tailBufferPosition.row, tailBufferPosition.column) - - handleGutterDrag: (tailRow, tailColumn) -> - tailPosition = [tailRow, tailColumn] if tailColumn? + @handleGutterDrag(new Range(tailScreenPosition, tailScreenPosition)) + handleGutterDrag: (initialRange) -> @handleDragUntilMouseUp (screenPosition) => - dragRow = @editor.bufferPositionForScreenPosition(screenPosition).row - if dragRow < tailRow - @editor.getLastSelection().setBufferRange([[dragRow, 0], tailPosition ? [tailRow + 1, 0]], reversed: true, autoscroll: false, preserveFolds: true) + dragRow = screenPosition.row + if dragRow < initialRange.start.row + startPosition = @editor.clipScreenPosition([dragRow, 0], skipSoftWrapIndentation: true) + screenRange = new Range(startPosition, startPosition).union(initialRange) + @editor.getLastSelection().setScreenRange(screenRange, reversed: true, autoscroll: false, preserveFolds: true) else - @editor.getLastSelection().setBufferRange([tailPosition ? [tailRow, 0], [dragRow + 1, 0]], reversed: false, autoscroll: false, preserveFolds: true) + endPosition = [dragRow + 1, 0] + screenRange = new Range(endPosition, endPosition).union(initialRange) + @editor.getLastSelection().setScreenRange(screenRange, reversed: false, autoscroll: false, preserveFolds: true) @editor.getLastCursor().autoscroll() onStylesheetsChanged: (styleElement) =>