mirror of
https://github.com/atom/atom.git
synced 2026-01-25 06:48:28 -05:00
Move cursor merging specs to edit-session-spec
This commit is contained in:
@@ -28,6 +28,15 @@ describe "EditSession", ->
|
||||
editSession.moveCursorDown()
|
||||
expect(editSession.getCursorScreenPosition().column).toBe 6
|
||||
|
||||
it "merges multiple cursors", ->
|
||||
editSession.setCursorScreenPosition([0, 0])
|
||||
editSession.addCursorAtScreenPosition([0, 1])
|
||||
[cursor1, cursor2] = editSession.getCursors()
|
||||
editSession.setCursorScreenPosition([4, 7])
|
||||
expect(editSession.getCursors().length).toBe 1
|
||||
expect(editSession.getCursors()).toEqual [cursor1]
|
||||
expect(editSession.getCursorScreenPosition()).toEqual [4, 7]
|
||||
|
||||
describe ".moveCursorUp()", ->
|
||||
it "moves the cursor up", ->
|
||||
editSession.setCursorScreenPosition([2, 2])
|
||||
@@ -56,6 +65,14 @@ describe "EditSession", ->
|
||||
editSession.moveCursorDown()
|
||||
expect(editSession.getCursorScreenPosition()).toEqual(row: 1, column: 4)
|
||||
|
||||
it "merges cursors when they overlap", ->
|
||||
editSession.addCursorAtScreenPosition([1, 0])
|
||||
[cursor1, cursor2] = editSession.getCursors()
|
||||
|
||||
editSession.moveCursorUp()
|
||||
expect(editSession.getCursors()).toEqual [cursor1]
|
||||
expect(cursor1.getBufferPosition()).toEqual [0,0]
|
||||
|
||||
describe ".moveCursorDown()", ->
|
||||
it "moves the cursor down", ->
|
||||
editSession.setCursorScreenPosition([2, 2])
|
||||
@@ -97,6 +114,15 @@ describe "EditSession", ->
|
||||
editSession.moveCursorUp()
|
||||
expect(editSession.getCursorScreenPosition().column).toBe 0
|
||||
|
||||
it "merges cursors when they overlap", ->
|
||||
editSession.setCursorScreenPosition([12, 2])
|
||||
editSession.addCursorAtScreenPosition([11, 2])
|
||||
[cursor1, cursor2] = editSession.getCursors()
|
||||
|
||||
editSession.moveCursorDown()
|
||||
expect(editSession.getCursors()).toEqual [cursor1]
|
||||
expect(cursor1.getBufferPosition()).toEqual [12,2]
|
||||
|
||||
describe ".moveCursorLeft()", ->
|
||||
it "moves the cursor by one column to the left", ->
|
||||
editSession.setCursorScreenPosition([3, 3])
|
||||
@@ -116,6 +142,15 @@ describe "EditSession", ->
|
||||
editSession.moveCursorLeft()
|
||||
expect(editSession.getCursorScreenPosition()).toEqual(row: 0, column: 0)
|
||||
|
||||
it "merges cursors when they overlap", ->
|
||||
editSession.setCursorScreenPosition([0, 0])
|
||||
editSession.addCursorAtScreenPosition([0, 1])
|
||||
|
||||
[cursor1, cursor2] = editSession.getCursors()
|
||||
editSession.moveCursorLeft()
|
||||
expect(editSession.getCursors()).toEqual [cursor1]
|
||||
expect(cursor1.getBufferPosition()).toEqual [0,0]
|
||||
|
||||
describe ".moveCursorRight()", ->
|
||||
it "moves the cursor by one column to the right", ->
|
||||
editSession.setCursorScreenPosition([3, 3])
|
||||
@@ -141,6 +176,15 @@ describe "EditSession", ->
|
||||
|
||||
expect(editSession.getCursorScreenPosition()).toEqual(lastPosition)
|
||||
|
||||
it "merges cursors when they overlap", ->
|
||||
editSession.setCursorScreenPosition([12, 2])
|
||||
editSession.addCursorAtScreenPosition([12, 1])
|
||||
[cursor1, cursor2] = editSession.getCursors()
|
||||
|
||||
editSession.moveCursorRight()
|
||||
expect(editSession.getCursors()).toEqual [cursor1]
|
||||
expect(cursor1.getBufferPosition()).toEqual [12,2]
|
||||
|
||||
describe ".moveCursorToTop()", ->
|
||||
it "moves the cursor to the top of the buffer", ->
|
||||
editSession.setCursorScreenPosition [11,1]
|
||||
@@ -882,3 +926,20 @@ describe "EditSession", ->
|
||||
expect(cursor2.getScreenPosition()).toEqual [0, 8]
|
||||
expect(cursor3.getScreenPosition()).toEqual [1, 0]
|
||||
|
||||
it "merges cursors when the change causes them to overlap", ->
|
||||
editSession.setCursorScreenPosition([0, 0])
|
||||
editSession.addCursorAtScreenPosition([0, 1])
|
||||
editSession.addCursorAtScreenPosition([1, 1])
|
||||
|
||||
[cursor1, cursor2, cursor3] = editSession.getCursors()
|
||||
expect(editSession.getCursors().length).toBe 3
|
||||
|
||||
editSession.backspace()
|
||||
expect(editSession.getCursors()).toEqual [cursor1, cursor3]
|
||||
expect(cursor1.getBufferPosition()).toEqual [0,0]
|
||||
expect(cursor3.getBufferPosition()).toEqual [1,0]
|
||||
|
||||
editSession.insertText "x"
|
||||
expect(editSession.lineForBufferRow(0)).toBe "xar quicksort = function () {"
|
||||
expect(editSession.lineForBufferRow(1)).toBe "x var sort = function(items) {"
|
||||
|
||||
|
||||
@@ -1368,72 +1368,6 @@ describe "Editor", ->
|
||||
expect(selection1.getScreenRange()).toEqual [[3, 10], [7, 4]]
|
||||
expect(selection1.isReversed()).toBeTruthy()
|
||||
|
||||
describe "cursor merging", ->
|
||||
it "merges cursors when they overlap due to a buffer change", ->
|
||||
editor.setCursorScreenPosition([0, 0])
|
||||
editor.addCursorAtScreenPosition([0, 1])
|
||||
editor.addCursorAtScreenPosition([1, 1])
|
||||
|
||||
[cursor1, cursor2, cursor3] = editor.getCursors()
|
||||
expect(editor.getCursors().length).toBe 3
|
||||
|
||||
editor.backspace()
|
||||
expect(editor.getCursors()).toEqual [cursor1, cursor3]
|
||||
expect(cursor1.getBufferPosition()).toEqual [0,0]
|
||||
expect(cursor3.getBufferPosition()).toEqual [1,0]
|
||||
|
||||
editor.insertText "x"
|
||||
expect(editor.lineForBufferRow(0)).toBe "xar quicksort = function () {"
|
||||
expect(editor.lineForBufferRow(1)).toBe "x var sort = function(items) {"
|
||||
|
||||
it "merges cursors when they overlap due to movement", ->
|
||||
editor.setCursorScreenPosition([0, 0])
|
||||
editor.addCursorAtScreenPosition([0, 1])
|
||||
|
||||
[cursor1, cursor2] = editor.getCursors()
|
||||
editor.moveCursorLeft()
|
||||
expect(editor.getCursors()).toEqual [cursor1]
|
||||
expect(cursor1.getBufferPosition()).toEqual [0,0]
|
||||
|
||||
editor.addCursorAtScreenPosition([1, 0])
|
||||
[cursor1, cursor2] = editor.getCursors()
|
||||
|
||||
editor.moveCursorUp()
|
||||
expect(editor.getCursors()).toEqual [cursor1]
|
||||
expect(cursor1.getBufferPosition()).toEqual [0,0]
|
||||
|
||||
editor.setCursorScreenPosition([12, 2])
|
||||
editor.addCursorAtScreenPosition([12, 1])
|
||||
[cursor1, cursor2] = editor.getCursors()
|
||||
|
||||
editor.moveCursorRight()
|
||||
expect(editor.getCursors()).toEqual [cursor1]
|
||||
expect(cursor1.getBufferPosition()).toEqual [12,2]
|
||||
|
||||
editor.addCursorAtScreenPosition([11, 2])
|
||||
[cursor1, cursor2] = editor.getCursors()
|
||||
|
||||
editor.moveCursorDown()
|
||||
expect(editor.getCursors()).toEqual [cursor1]
|
||||
expect(cursor1.getBufferPosition()).toEqual [12,2]
|
||||
|
||||
it "merges cursors when the mouse is clicked without the meta-key", ->
|
||||
editor.attachToDom()
|
||||
editor.setCursorScreenPosition([0, 0])
|
||||
editor.addCursorAtScreenPosition([0, 1])
|
||||
|
||||
[cursor1, cursor2] = editor.getCursors()
|
||||
editor.renderedLines.trigger mousedownEvent(editor: editor, point: [4, 7])
|
||||
expect(editor.getCursors().length).toBe 1
|
||||
expect(editor.getCursors()).toEqual [cursor1]
|
||||
expect(cursor1.getBufferPosition()).toEqual [4, 7]
|
||||
|
||||
editor.renderedLines.trigger mousemoveEvent(editor: editor, point: [5, 27])
|
||||
|
||||
selections = editor.getSelections()
|
||||
expect(selections.length).toBe 1
|
||||
expect(selections[0].getBufferRange()).toEqual [[4,7], [5,27]]
|
||||
|
||||
describe "buffer manipulation", ->
|
||||
beforeEach ->
|
||||
editor.attachToDom()
|
||||
|
||||
Reference in New Issue
Block a user