2014-09-23 01:31:03 +04:00
|
|
|
Editor = require '../src/text-editor'
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
describe "Selection", ->
|
2013-11-20 03:22:47 +04:00
|
|
|
[buffer, editor, selection] = []
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
beforeEach ->
|
2013-11-21 03:35:49 +04:00
|
|
|
buffer = atom.project.bufferForPathSync('sample.js')
|
2014-01-04 04:42:11 +04:00
|
|
|
editor = new Editor(buffer: buffer, tabLength: 2)
|
2014-08-29 04:51:16 +04:00
|
|
|
selection = editor.getLastSelection()
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
afterEach ->
|
|
|
|
buffer.destroy()
|
|
|
|
|
|
|
|
describe ".deleteSelectedText()", ->
|
|
|
|
describe "when nothing is selected", ->
|
|
|
|
it "deletes nothing", ->
|
2013-07-23 04:39:46 +04:00
|
|
|
selection.setBufferRange [[0,3], [0,3]]
|
2012-08-28 02:36:36 +04:00
|
|
|
selection.deleteSelectedText()
|
|
|
|
expect(buffer.lineForRow(0)).toBe "var quicksort = function () {"
|
|
|
|
|
|
|
|
describe "when one line is selected", ->
|
|
|
|
it "deletes selected text and clears the selection", ->
|
2013-07-23 04:39:46 +04:00
|
|
|
selection.setBufferRange [[0,4], [0,14]]
|
2012-08-28 02:36:36 +04:00
|
|
|
selection.deleteSelectedText()
|
|
|
|
expect(buffer.lineForRow(0)).toBe "var = function () {"
|
|
|
|
|
|
|
|
endOfLine = buffer.lineForRow(0).length
|
2013-07-23 04:39:46 +04:00
|
|
|
selection.setBufferRange [[0,0], [0, endOfLine]]
|
2012-08-28 02:36:36 +04:00
|
|
|
selection.deleteSelectedText()
|
|
|
|
expect(buffer.lineForRow(0)).toBe ""
|
|
|
|
|
|
|
|
expect(selection.isEmpty()).toBeTruthy()
|
|
|
|
|
|
|
|
describe "when multiple lines are selected", ->
|
|
|
|
it "deletes selected text and clears the selection", ->
|
2013-07-23 04:39:46 +04:00
|
|
|
selection.setBufferRange [[0,1], [2,39]]
|
2012-08-28 02:36:36 +04:00
|
|
|
selection.deleteSelectedText()
|
|
|
|
expect(buffer.lineForRow(0)).toBe "v;"
|
|
|
|
expect(selection.isEmpty()).toBeTruthy()
|
|
|
|
|
2013-02-03 03:44:13 +04:00
|
|
|
describe "when the cursor precedes the tail", ->
|
2012-12-13 22:11:37 +04:00
|
|
|
it "deletes selected text and clears the selection", ->
|
2012-08-28 02:36:36 +04:00
|
|
|
selection.cursor.setScreenPosition [0,13]
|
|
|
|
selection.selectToScreenPosition [0,4]
|
|
|
|
|
|
|
|
selection.delete()
|
|
|
|
expect(buffer.lineForRow(0)).toBe "var = function () {"
|
|
|
|
expect(selection.isEmpty()).toBeTruthy()
|
|
|
|
|
|
|
|
describe ".isReversed()", ->
|
2013-02-03 03:44:13 +04:00
|
|
|
it "returns true if the cursor precedes the tail", ->
|
2012-08-28 02:36:36 +04:00
|
|
|
selection.cursor.setScreenPosition([0, 20])
|
|
|
|
selection.selectToScreenPosition([0, 10])
|
|
|
|
expect(selection.isReversed()).toBeTruthy()
|
|
|
|
|
|
|
|
selection.selectToScreenPosition([0, 25])
|
|
|
|
expect(selection.isReversed()).toBeFalsy()
|
|
|
|
|
2013-02-03 03:44:13 +04:00
|
|
|
describe "when only the selection's tail is moved (regression)", ->
|
2014-09-05 00:40:12 +04:00
|
|
|
it "notifies ::onDidChangeRange observers", ->
|
2014-04-24 03:22:34 +04:00
|
|
|
selection.setBufferRange([[2, 0], [2, 10]], reversed: true)
|
2012-08-28 02:36:36 +04:00
|
|
|
changeScreenRangeHandler = jasmine.createSpy('changeScreenRangeHandler')
|
2014-09-05 00:40:12 +04:00
|
|
|
selection.onDidChangeRange changeScreenRangeHandler
|
2012-08-28 02:36:36 +04:00
|
|
|
|
|
|
|
buffer.insert([2, 5], 'abc')
|
|
|
|
expect(changeScreenRangeHandler).toHaveBeenCalled()
|
|
|
|
|
|
|
|
describe "when the selection is destroyed", ->
|
2013-02-03 03:41:57 +04:00
|
|
|
it "destroys its marker", ->
|
2012-08-28 02:36:36 +04:00
|
|
|
selection.setBufferRange([[2, 0], [2, 10]])
|
|
|
|
selection.destroy()
|
2013-04-29 20:23:30 +04:00
|
|
|
expect(selection.marker.isDestroyed()).toBeTruthy()
|