mirror of
https://github.com/atom/atom.git
synced 2026-01-25 06:48:28 -05:00
Start moving specs from editor-spec to edit-session-spec
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
Buffer = require 'buffer'
|
||||
EditSession = require 'edit-session'
|
||||
|
||||
fdescribe "EditSession", ->
|
||||
describe "EditSession", ->
|
||||
[buffer, editSession, lineLengths] = []
|
||||
|
||||
beforeEach ->
|
||||
|
||||
@@ -891,231 +891,6 @@ describe "Editor", ->
|
||||
expect(editor.renderedLines.find(".line").length).toBeGreaterThan originalLineCount
|
||||
|
||||
describe "cursor movement", ->
|
||||
describe "when the arrow keys are pressed", ->
|
||||
it "moves the cursor by a single row/column", ->
|
||||
editor.trigger keydownEvent('right')
|
||||
expect(editor.getCursorScreenPosition()).toEqual(row: 0, column: 1)
|
||||
|
||||
editor.trigger keydownEvent('down')
|
||||
expect(editor.getCursorScreenPosition()).toEqual(row: 1, column: 1)
|
||||
|
||||
editor.trigger keydownEvent('left')
|
||||
expect(editor.getCursorScreenPosition()).toEqual(row: 1, column: 0)
|
||||
|
||||
editor.trigger keydownEvent('up')
|
||||
expect(editor.getCursorScreenPosition()).toEqual(row: 0, column: 0)
|
||||
|
||||
describe "vertical movement", ->
|
||||
describe "goal column retention", ->
|
||||
lineLengths = null
|
||||
|
||||
beforeEach ->
|
||||
lineLengths = buffer.getLines().map (line) -> line.length
|
||||
expect(lineLengths[3]).toBeGreaterThan(lineLengths[4])
|
||||
expect(lineLengths[5]).toBeGreaterThan(lineLengths[4])
|
||||
expect(lineLengths[6]).toBeGreaterThan(lineLengths[3])
|
||||
|
||||
it "retains the goal column when moving up", ->
|
||||
expect(lineLengths[6]).toBeGreaterThan(32)
|
||||
editor.setCursorScreenPosition(row: 6, column: 32)
|
||||
|
||||
editor.moveCursorUp()
|
||||
expect(editor.getCursorScreenPosition().column).toBe lineLengths[5]
|
||||
|
||||
editor.moveCursorUp()
|
||||
expect(editor.getCursorScreenPosition().column).toBe lineLengths[4]
|
||||
|
||||
editor.moveCursorUp()
|
||||
expect(editor.getCursorScreenPosition().column).toBe 32
|
||||
|
||||
it "retains the goal column when moving down", ->
|
||||
editor.setCursorScreenPosition(row: 3, column: lineLengths[3])
|
||||
|
||||
editor.moveCursorDown()
|
||||
expect(editor.getCursorScreenPosition().column).toBe lineLengths[4]
|
||||
|
||||
editor.moveCursorDown()
|
||||
expect(editor.getCursorScreenPosition().column).toBe lineLengths[5]
|
||||
|
||||
editor.moveCursorDown()
|
||||
expect(editor.getCursorScreenPosition().column).toBe lineLengths[3]
|
||||
|
||||
it "clears the goal column when the cursor is set", ->
|
||||
# set a goal column by moving down
|
||||
editor.setCursorScreenPosition(row: 3, column: lineLengths[3])
|
||||
editor.moveCursorDown()
|
||||
expect(editor.getCursorScreenPosition().column).not.toBe 6
|
||||
|
||||
# clear the goal column by explicitly setting the cursor position
|
||||
editor.setCursorScreenPosition([4,6])
|
||||
expect(editor.getCursorScreenPosition().column).toBe 6
|
||||
|
||||
editor.moveCursorDown()
|
||||
expect(editor.getCursorScreenPosition().column).toBe 6
|
||||
|
||||
describe "when up is pressed on the first line", ->
|
||||
it "moves the cursor to the beginning of the line, but retains the goal column", ->
|
||||
editor.setCursorScreenPosition(row: 0, column: 4)
|
||||
editor.moveCursorUp()
|
||||
expect(editor.getCursorScreenPosition()).toEqual(row: 0, column: 0)
|
||||
|
||||
editor.moveCursorDown()
|
||||
expect(editor.getCursorScreenPosition()).toEqual(row: 1, column: 4)
|
||||
|
||||
describe "when down is pressed on the last line", ->
|
||||
it "moves the cursor to the end of line, but retains the goal column", ->
|
||||
lastLineIndex = buffer.getLines().length - 1
|
||||
lastLine = buffer.lineForRow(lastLineIndex)
|
||||
expect(lastLine.length).toBeGreaterThan(0)
|
||||
|
||||
editor.setCursorScreenPosition(row: lastLineIndex, column: 1)
|
||||
editor.moveCursorDown()
|
||||
expect(editor.getCursorScreenPosition()).toEqual(row: lastLineIndex, column: lastLine.length)
|
||||
|
||||
editor.moveCursorUp()
|
||||
expect(editor.getCursorScreenPosition().column).toBe 1
|
||||
|
||||
it "retains a goal column of 0", ->
|
||||
lastLineIndex = buffer.getLines().length - 1
|
||||
lastLine = buffer.lineForRow(lastLineIndex)
|
||||
expect(lastLine.length).toBeGreaterThan(0)
|
||||
|
||||
editor.setCursorScreenPosition(row: lastLineIndex, column: 0)
|
||||
editor.moveCursorDown()
|
||||
editor.moveCursorUp()
|
||||
expect(editor.getCursorScreenPosition().column).toBe 0
|
||||
|
||||
describe "horizontal movement", ->
|
||||
describe "when left is pressed on the first column", ->
|
||||
describe "when there is a previous line", ->
|
||||
it "wraps to the end of the previous line", ->
|
||||
editor.setCursorScreenPosition(row: 1, column: 0)
|
||||
editor.moveCursorLeft()
|
||||
expect(editor.getCursorScreenPosition()).toEqual(row: 0, column: buffer.lineForRow(0).length)
|
||||
|
||||
describe "when the cursor is on the first line", ->
|
||||
it "remains in the same position (0,0)", ->
|
||||
editor.setCursorScreenPosition(row: 0, column: 0)
|
||||
editor.moveCursorLeft()
|
||||
expect(editor.getCursorScreenPosition()).toEqual(row: 0, column: 0)
|
||||
|
||||
describe "when right is pressed on the last column", ->
|
||||
describe "when there is a subsequent line", ->
|
||||
it "wraps to the beginning of the next line", ->
|
||||
editor.setCursorScreenPosition(row: 0, column: buffer.lineForRow(0).length)
|
||||
editor.moveCursorRight()
|
||||
expect(editor.getCursorScreenPosition()).toEqual(row: 1, column: 0)
|
||||
|
||||
describe "when the cursor is on the last line", ->
|
||||
it "remains in the same position", ->
|
||||
lastLineIndex = buffer.getLines().length - 1
|
||||
lastLine = buffer.lineForRow(lastLineIndex)
|
||||
expect(lastLine.length).toBeGreaterThan(0)
|
||||
|
||||
lastPosition = { row: lastLineIndex, column: lastLine.length }
|
||||
editor.setCursorScreenPosition(lastPosition)
|
||||
editor.moveCursorRight()
|
||||
|
||||
expect(editor.getCursorScreenPosition()).toEqual(lastPosition)
|
||||
|
||||
describe "move-to-top ", ->
|
||||
it "moves cusor to the top of the buffer", ->
|
||||
editor.setCursorScreenPosition [11,1]
|
||||
editor.addCursorAtScreenPosition [12,0]
|
||||
editor.trigger 'move-to-top'
|
||||
expect(editor.getCursors().length).toBe 1
|
||||
expect(editor.getCursorBufferPosition()).toEqual [0,0]
|
||||
|
||||
describe "move-to-bottom", ->
|
||||
it "moves cusor to the bottom of the buffer", ->
|
||||
editor.setCursorScreenPosition [0,0]
|
||||
editor.addCursorAtScreenPosition [1,0]
|
||||
editor.trigger 'move-to-bottom'
|
||||
expect(editor.getCursors().length).toBe 1
|
||||
expect(editor.getCursorBufferPosition()).toEqual [12,2]
|
||||
|
||||
describe "move-to-beginning-of-line", ->
|
||||
it "moves cursor to the beginning of line", ->
|
||||
editor.setCursorScreenPosition [0,5]
|
||||
editor.addCursorAtScreenPosition [1,7]
|
||||
editor.trigger 'move-to-beginning-of-line'
|
||||
expect(editor.getCursors().length).toBe 2
|
||||
[cursor1, cursor2] = editor.getCursors()
|
||||
expect(cursor1.getBufferPosition()).toEqual [0,0]
|
||||
expect(cursor2.getBufferPosition()).toEqual [1,0]
|
||||
|
||||
describe "move-to-end-of-line", ->
|
||||
it "moves cursor to the end of line", ->
|
||||
editor.setCursorScreenPosition [0,0]
|
||||
editor.addCursorAtScreenPosition [1,0]
|
||||
editor.trigger 'move-to-end-of-line'
|
||||
expect(editor.getCursors().length).toBe 2
|
||||
[cursor1, cursor2] = editor.getCursors()
|
||||
expect(cursor1.getBufferPosition()).toEqual [0,29]
|
||||
expect(cursor2.getBufferPosition()).toEqual [1,30]
|
||||
|
||||
describe "move-to-first-character-of-line", ->
|
||||
it "moves to the first character of the current line or the beginning of the line if it's already on the first character", ->
|
||||
editor.setCursorScreenPosition [0,5]
|
||||
editor.addCursorAtScreenPosition [1,7]
|
||||
editor.trigger 'move-to-first-character-of-line'
|
||||
[cursor1, cursor2] = editor.getCursors()
|
||||
expect(cursor1.getBufferPosition()).toEqual [0,0]
|
||||
expect(cursor2.getBufferPosition()).toEqual [1,2]
|
||||
editor.trigger 'move-to-first-character-of-line'
|
||||
expect(cursor1.getBufferPosition()).toEqual [0,0]
|
||||
expect(cursor2.getBufferPosition()).toEqual [1,0]
|
||||
|
||||
it "does not throw an exception on an empty line", ->
|
||||
editor.setCursorBufferPosition([10, 0])
|
||||
editor.trigger 'move-to-first-character-of-line'
|
||||
|
||||
describe "move-to-next-word", ->
|
||||
it "moves the cursor to the next word or the end of file if there is no next word", ->
|
||||
editor.setCursorBufferPosition [2, 5]
|
||||
editor.addCursorAtBufferPosition [3, 60]
|
||||
[cursor1, cursor2] = editor.getCursors()
|
||||
|
||||
editor.trigger 'move-to-next-word'
|
||||
|
||||
expect(cursor1.getBufferPosition()).toEqual [2, 7]
|
||||
expect(cursor2.getBufferPosition()).toEqual [4, 4]
|
||||
|
||||
buffer.insert([12, 2], ' ')
|
||||
cursor1.setBufferPosition([12, 1])
|
||||
editor.trigger 'move-to-next-word'
|
||||
expect(cursor1.getBufferPosition()).toEqual [12, 5]
|
||||
|
||||
describe "move-to-beginning-of-word", ->
|
||||
it "moves the cursor to the beginning of the word", ->
|
||||
editor.setCursorBufferPosition [0, 8]
|
||||
editor.addCursorAtBufferPosition [1, 12]
|
||||
editor.addCursorAtBufferPosition [3, 0]
|
||||
[cursor1, cursor2, cursor3] = editor.getCursors()
|
||||
|
||||
editor.trigger 'move-to-beginning-of-word'
|
||||
|
||||
expect(cursor1.getBufferPosition()).toEqual [0, 4]
|
||||
expect(cursor2.getBufferPosition()).toEqual [1, 11]
|
||||
expect(cursor3.getBufferPosition()).toEqual [2, 39]
|
||||
|
||||
it "does not fail at position [0, 0]", ->
|
||||
editor.setCursorBufferPosition([0, 0])
|
||||
editor.trigger 'move-to-beginning-of-word'
|
||||
|
||||
describe "move-to-end-of-word", ->
|
||||
it "moves the cursor to the end of the word", ->
|
||||
editor.setCursorBufferPosition [0, 6]
|
||||
editor.addCursorAtBufferPosition [1, 10]
|
||||
editor.addCursorAtBufferPosition [2, 40]
|
||||
[cursor1, cursor2, cursor3] = editor.getCursors()
|
||||
|
||||
editor.trigger 'move-to-end-of-word'
|
||||
|
||||
expect(cursor1.getBufferPosition()).toEqual [0, 13]
|
||||
expect(cursor2.getBufferPosition()).toEqual [1, 12]
|
||||
expect(cursor3.getBufferPosition()).toEqual [3, 7]
|
||||
|
||||
describe ".setCursorScreenPosition({row, column})", ->
|
||||
beforeEach ->
|
||||
editor.attachToDom()
|
||||
@@ -1409,61 +1184,6 @@ describe "Editor", ->
|
||||
beforeEach ->
|
||||
selection = editor.getSelection()
|
||||
|
||||
describe "when the arrow keys are pressed with the shift modifier", ->
|
||||
it "expands the selection up to the cursor's new location", ->
|
||||
editor.setCursorScreenPosition(row: 1, column: 6)
|
||||
|
||||
expect(selection.isEmpty()).toBeTruthy()
|
||||
|
||||
editor.trigger keydownEvent('right', shiftKey: true)
|
||||
|
||||
expect(selection.isEmpty()).toBeFalsy()
|
||||
range = selection.getScreenRange()
|
||||
expect(range.start).toEqual(row: 1, column: 6)
|
||||
expect(range.end).toEqual(row: 1, column: 7)
|
||||
|
||||
editor.trigger keydownEvent('right', shiftKey: true)
|
||||
range = selection.getScreenRange()
|
||||
expect(range.start).toEqual(row: 1, column: 6)
|
||||
expect(range.end).toEqual(row: 1, column: 8)
|
||||
|
||||
editor.trigger keydownEvent('down', shiftKey: true)
|
||||
range = selection.getScreenRange()
|
||||
expect(range.start).toEqual(row: 1, column: 6)
|
||||
expect(range.end).toEqual(row: 2, column: 8)
|
||||
|
||||
editor.trigger keydownEvent('left', shiftKey: true)
|
||||
range = selection.getScreenRange()
|
||||
expect(range.start).toEqual(row: 1, column: 6)
|
||||
expect(range.end).toEqual(row: 2, column: 7)
|
||||
|
||||
editor.trigger keydownEvent('up', shiftKey: true)
|
||||
range = selection.getScreenRange()
|
||||
expect(range.start).toEqual(row: 1, column: 6)
|
||||
expect(range.end).toEqual(row: 1, column: 7)
|
||||
|
||||
describe "when the arrow keys are pressed without the shift modifier", ->
|
||||
makeNonEmpty = ->
|
||||
selection.setBufferRange(new Range({row: 1, column: 2}, {row: 1, column: 5}))
|
||||
expect(selection.isEmpty()).toBeFalsy()
|
||||
|
||||
it "clears the selection", ->
|
||||
makeNonEmpty()
|
||||
editor.trigger keydownEvent('right')
|
||||
expect(selection.isEmpty()).toBeTruthy()
|
||||
|
||||
makeNonEmpty()
|
||||
editor.trigger keydownEvent('left')
|
||||
expect(selection.isEmpty()).toBeTruthy()
|
||||
|
||||
makeNonEmpty()
|
||||
editor.trigger keydownEvent('up')
|
||||
expect(selection.isEmpty()).toBeTruthy()
|
||||
|
||||
makeNonEmpty()
|
||||
editor.trigger keydownEvent('down')
|
||||
expect(selection.isEmpty()).toBeTruthy()
|
||||
|
||||
describe "when the mouse is dragged across the text", ->
|
||||
it "creates a selection from the initial click to mouse cursor's location ", ->
|
||||
editor.attachToDom()
|
||||
@@ -1572,99 +1292,6 @@ describe "Editor", ->
|
||||
editor.renderedLines.trigger mousedownEvent(editor: editor, point: [5, 24], shiftKey: true, originalEvent: { detail: 3 })
|
||||
expect(editor.getSelection().getScreenRange()).toEqual [[4, 7], [5, 30]]
|
||||
|
||||
describe "select-to-top", ->
|
||||
it "selects text from cusor position to the top of the buffer", ->
|
||||
editor.setCursorScreenPosition [11,2]
|
||||
editor.addCursorAtScreenPosition [10,0]
|
||||
editor.trigger 'select-to-top'
|
||||
expect(editor.getCursors().length).toBe 1
|
||||
expect(editor.getCursorBufferPosition()).toEqual [0,0]
|
||||
expect(editor.getSelection().getBufferRange()).toEqual [[0,0], [11,2]]
|
||||
expect(editor.getSelection().isReversed()).toBeTruthy()
|
||||
|
||||
describe "select-to-bottom", ->
|
||||
it "selects text from cusor position to the bottom of the buffer", ->
|
||||
editor.setCursorScreenPosition [10,0]
|
||||
editor.addCursorAtScreenPosition [9,3]
|
||||
editor.trigger 'select-to-bottom'
|
||||
expect(editor.getCursors().length).toBe 1
|
||||
expect(editor.getCursorBufferPosition()).toEqual [12,2]
|
||||
expect(editor.getSelection().getBufferRange()).toEqual [[9,3], [12,2]]
|
||||
expect(editor.getSelection().isReversed()).toBeFalsy()
|
||||
|
||||
describe "select-all", ->
|
||||
it "selects the entire buffer", ->
|
||||
editor.trigger 'select-all'
|
||||
expect(editor.getSelection().getBufferRange()).toEqual buffer.getRange()
|
||||
|
||||
describe "select-to-beginning-of-line", ->
|
||||
it "selects text from cusor position to beginning of line", ->
|
||||
editor.setCursorScreenPosition [12,2]
|
||||
editor.addCursorAtScreenPosition [11,3]
|
||||
editor.trigger 'select-to-beginning-of-line'
|
||||
expect(editor.getCursors().length).toBe 2
|
||||
[cursor1, cursor2] = editor.getCursors()
|
||||
expect(cursor1.getBufferPosition()).toEqual [12,0]
|
||||
expect(cursor2.getBufferPosition()).toEqual [11,0]
|
||||
|
||||
expect(editor.getSelections().length).toBe 2
|
||||
[selection1, selection2] = editor.getSelections()
|
||||
expect(selection1.getBufferRange()).toEqual [[12,0], [12,2]]
|
||||
expect(selection1.isReversed()).toBeTruthy()
|
||||
expect(selection2.getBufferRange()).toEqual [[11,0], [11,3]]
|
||||
expect(selection2.isReversed()).toBeTruthy()
|
||||
|
||||
describe "select-to-end-of-line", ->
|
||||
it "selects text from cusor position to end of line", ->
|
||||
editor.setCursorScreenPosition [12,0]
|
||||
editor.addCursorAtScreenPosition [11,3]
|
||||
editor.trigger 'select-to-end-of-line'
|
||||
expect(editor.getCursors().length).toBe 2
|
||||
[cursor1, cursor2] = editor.getCursors()
|
||||
expect(cursor1.getBufferPosition()).toEqual [12,2]
|
||||
expect(cursor2.getBufferPosition()).toEqual [11,44]
|
||||
|
||||
expect(editor.getSelections().length).toBe 2
|
||||
[selection1, selection2] = editor.getSelections()
|
||||
expect(selection1.getBufferRange()).toEqual [[12,0], [12,2]]
|
||||
expect(selection1.isReversed()).toBeFalsy()
|
||||
expect(selection2.getBufferRange()).toEqual [[11,3], [11,44]]
|
||||
expect(selection2.isReversed()).toBeFalsy()
|
||||
|
||||
describe "select-to-beginning-of-word", ->
|
||||
it "selects text from cusor position to beginning of word", ->
|
||||
editor.setCursorScreenPosition [0,13]
|
||||
editor.addCursorAtScreenPosition [3,49]
|
||||
editor.trigger 'select-to-beginning-of-word'
|
||||
expect(editor.getCursors().length).toBe 2
|
||||
[cursor1, cursor2] = editor.getCursors()
|
||||
expect(cursor1.getBufferPosition()).toEqual [0,4]
|
||||
expect(cursor2.getBufferPosition()).toEqual [3,47]
|
||||
|
||||
expect(editor.getSelections().length).toBe 2
|
||||
[selection1, selection2] = editor.getSelections()
|
||||
expect(selection1.getBufferRange()).toEqual [[0,4], [0,13]]
|
||||
expect(selection1.isReversed()).toBeTruthy()
|
||||
expect(selection2.getBufferRange()).toEqual [[3,47], [3,49]]
|
||||
expect(selection2.isReversed()).toBeTruthy()
|
||||
|
||||
describe "select-to-end-of-word", ->
|
||||
it "selects text from cusor position to end of word", ->
|
||||
editor.setCursorScreenPosition [0,4]
|
||||
editor.addCursorAtScreenPosition [3,48]
|
||||
editor.trigger 'select-to-end-of-word'
|
||||
expect(editor.getCursors().length).toBe 2
|
||||
[cursor1, cursor2] = editor.getCursors()
|
||||
expect(cursor1.getBufferPosition()).toEqual [0,13]
|
||||
expect(cursor2.getBufferPosition()).toEqual [3,50]
|
||||
|
||||
expect(editor.getSelections().length).toBe 2
|
||||
[selection1, selection2] = editor.getSelections()
|
||||
expect(selection1.getBufferRange()).toEqual [[0,4], [0,13]]
|
||||
expect(selection1.isReversed()).toBeFalsy()
|
||||
expect(selection2.getBufferRange()).toEqual [[3,48], [3,50]]
|
||||
expect(selection2.isReversed()).toBeFalsy()
|
||||
|
||||
describe "multiple cursors", ->
|
||||
it "places multiple cursors with meta-click", ->
|
||||
editor.attachToDom()
|
||||
|
||||
Reference in New Issue
Block a user