Selection merging with mouse maintains directionality of last selection

This commit is contained in:
Nathan Sobo
2012-03-27 11:52:55 -07:00
parent e62e062f9b
commit 461fdd5e61
5 changed files with 23 additions and 11 deletions

View File

@@ -1030,7 +1030,7 @@ describe "Editor", ->
expect(selection1.getScreenRange()).toEqual [[4, 10], [5, 27]]
expect(selection2.getScreenRange()).toEqual [[6, 10], [8, 27]]
it "merges selections when they intersect", ->
it "merges selections when they intersect, maintaining the directionality of the newest selection", ->
editor.attachToDom()
editor.lines.trigger mousedownEvent(editor: editor, point: [4, 10])
editor.lines.trigger mousemoveEvent(editor: editor, point: [5, 27])
@@ -1044,6 +1044,17 @@ describe "Editor", ->
expect(selections.length).toBe 1
[selection1] = selections
expect(selection1.getScreenRange()).toEqual [[3, 10], [6, 27]]
expect(selection1.isReversed()).toBeFalsy()
editor.lines.trigger mousedownEvent(editor: editor, point: [7, 4], metaKey: true)
editor.lines.trigger mousemoveEvent(editor: editor, point: [4, 11], metaKey: true)
editor.lines.trigger 'mouseup'
selections = editor.compositeSelection.getSelections()
expect(selections.length).toBe 1
[selection1] = selections
expect(selection1.getScreenRange()).toEqual [[3, 10], [7, 4]]
expect(selection1.isReversed()).toBeTruthy()
describe "upon moving the cursor with the arrow keys with the shift key held down", ->
it "resizes all selections", ->

View File

@@ -41,7 +41,7 @@ class CompositeSeleciton
@modifySelectedText (selection) -> selection.delete()
selectToScreenPosition: (position) ->
@lastSelection().selectToScreenPosition(position)
@getLastSelection().selectToScreenPosition(position)
selectRight: ->
selection.selectRight() for selection in @getSelections()
@@ -60,15 +60,15 @@ class CompositeSeleciton
@mergeIntersectingSelections()
setBufferRange: (bufferRange, options) ->
@lastSelection().setBufferRange(bufferRange, options)
@getLastSelection().setBufferRange(bufferRange, options)
getBufferRange: (bufferRange) ->
@lastSelection().getBufferRange()
@getLastSelection().getBufferRange()
getText: ->
@lastSelection().getText()
@getLastSelection().getText()
lastSelection: ->
getLastSelection: ->
_.last(@selections)
mergeIntersectingSelections: (options) ->

View File

@@ -138,9 +138,9 @@ class Editor extends View
else
@setCursorScreenPosition(screenPosition)
else if clickCount == 2
@compositeSelection.lastSelection().selectWord()
@compositeSelection.getLastSelection().selectWord()
else if clickCount >= 3
@compositeSelection.lastSelection().selectLine()
@compositeSelection.getLastSelection().selectLine()
@selectOnMousemoveUntilMouseup()
@@ -167,7 +167,8 @@ class Editor extends View
@on 'mousemove', moveHandler
$(document).one 'mouseup', =>
@off 'mousemove', moveHandler
@compositeSelection.mergeIntersectingSelections()
reverse = @compositeSelection.getLastSelection().isReversed()
@compositeSelection.mergeIntersectingSelections({reverse})
renderLines: ->
@lineCache = []

View File

@@ -140,7 +140,7 @@ class Selection extends View
@getBufferRange().isEmpty()
isReversed: ->
@cursor.getBufferPosition().isLessThan(@anchorBufferPosition)
not @isEmpty() and @cursor.getBufferPosition().isLessThan(@anchorBufferPosition)
intersectsWith: (otherSelection) ->
@getScreenRange().intersectsWith(otherSelection.getScreenRange())

View File

@@ -22,4 +22,4 @@ module.exports.runSpecSuite = (specSuite, logErrors=true) ->
jasmineEnv = jasmine.getEnv()
jasmineEnv.addReporter(reporter)
jasmineEnv.specFilter = (spec) -> reporter.specFilter(spec)
jasmineEnv.execute()
jasmineEnv.execute()