Add specs for EditSession.proto.selectToScreenPosition. Move coverage of selection merging

This commit is contained in:
Nathan Sobo
2012-06-12 13:37:01 -06:00
parent 869df0bbc6
commit 4f50a4735d
2 changed files with 33 additions and 26 deletions

View File

@@ -348,6 +348,39 @@ describe "EditSession", ->
expect(selection1.getScreenRange()).toEqual([[0, 9], [1, 21]])
expect(selection1.isReversed()).toBeFalsy()
describe ".selectToScreenPosition(screenPosition)", ->
it "expands the last selection to the given position", ->
editSession.setSelectedBufferRange([[3, 0], [4, 5]])
editSession.addCursorAtScreenPosition([5, 5])
editSession.selectToScreenPosition([6, 1])
selections = editSession.getSelections()
expect(selections.length).toBe 2
[selection1, selection2] = selections
expect(selection1.getScreenRange()).toEqual [[3, 0], [4, 5]]
expect(selection2.getScreenRange()).toEqual [[5, 5], [6, 1]]
it "merges selections if they intersect, maintaining the directionality of the last selection", ->
editSession.setCursorScreenPosition([4, 10])
editSession.selectToScreenPosition([5, 27])
editSession.addCursorAtScreenPosition([3, 10])
editSession.selectToScreenPosition([6, 27])
selections = editSession.getSelections()
expect(selections.length).toBe 1
[selection1] = selections
expect(selection1.getScreenRange()).toEqual [[3, 10], [6, 27]]
expect(selection1.isReversed()).toBeFalsy()
editSession.addCursorAtScreenPosition([7, 4])
editSession.selectToScreenPosition([4, 11])
selections = editSession.getSelections()
expect(selections.length).toBe 1
[selection1] = selections
expect(selection1.getScreenRange()).toEqual [[3, 10], [7, 4]]
expect(selection1.isReversed()).toBeTruthy()
describe ".selectToTop()", ->
it "selects text from cusor position to the top of the buffer", ->
editSession.setCursorScreenPosition [11,2]

View File

@@ -1342,32 +1342,6 @@ describe "Editor", ->
expect(selection1.getScreenRange()).toEqual [[4, 10], [5, 27]]
expect(selection2.getScreenRange()).toEqual [[6, 10], [8, 27]]
it "merges selections when they intersect, maintaining the directionality of the newest selection", ->
editor.attachToDom()
editor.renderedLines.trigger mousedownEvent(editor: editor, point: [4, 10])
editor.renderedLines.trigger mousemoveEvent(editor: editor, point: [5, 27])
editor.renderedLines.trigger 'mouseup'
editor.renderedLines.trigger mousedownEvent(editor: editor, point: [3, 10], metaKey: true)
editor.renderedLines.trigger mousemoveEvent(editor: editor, point: [6, 27], metaKey: true)
editor.renderedLines.trigger 'mouseup'
selections = editor.getSelections()
expect(selections.length).toBe 1
[selection1] = selections
expect(selection1.getScreenRange()).toEqual [[3, 10], [6, 27]]
expect(selection1.isReversed()).toBeFalsy()
editor.renderedLines.trigger mousedownEvent(editor: editor, point: [7, 4], metaKey: true)
editor.renderedLines.trigger mousemoveEvent(editor: editor, point: [4, 11], metaKey: true)
editor.renderedLines.trigger 'mouseup'
selections = editor.getSelections()
expect(selections.length).toBe 1
[selection1] = selections
expect(selection1.getScreenRange()).toEqual [[3, 10], [7, 4]]
expect(selection1.isReversed()).toBeTruthy()
describe "buffer manipulation", ->
beforeEach ->
editor.attachToDom()