mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Make EditSession specs match vim style word behavior
This commit is contained in:
@@ -266,7 +266,7 @@ describe "EditSession", ->
|
||||
editSession.moveCursorToFirstCharacterOfLine()
|
||||
expect(editSession.getCursorBufferPosition()).toEqual [10, 0]
|
||||
|
||||
fdescribe ".moveCursorToBeginningOfWord()", ->
|
||||
describe ".moveCursorToBeginningOfWord()", ->
|
||||
it "moves the cursor to the beginning of the word", ->
|
||||
editSession.setCursorBufferPosition [0, 8]
|
||||
editSession.addCursorAtBufferPosition [1, 12]
|
||||
@@ -293,7 +293,7 @@ describe "EditSession", ->
|
||||
editSession.moveCursorToBeginningOfWord()
|
||||
expect(editSession.getCursorBufferPosition()).toEqual [9, 2]
|
||||
|
||||
fdescribe ".moveCursorToEndOfWord()", ->
|
||||
describe ".moveCursorToEndOfWord()", ->
|
||||
it "moves the cursor to the end of the word", ->
|
||||
editSession.setCursorBufferPosition [0, 6]
|
||||
editSession.addCursorAtBufferPosition [1, 10]
|
||||
@@ -534,13 +534,13 @@ describe "EditSession", ->
|
||||
expect(editSession.getCursors().length).toBe 2
|
||||
[cursor1, cursor2] = editSession.getCursors()
|
||||
expect(cursor1.getBufferPosition()).toEqual [0,4]
|
||||
expect(cursor2.getBufferPosition()).toEqual [3,44]
|
||||
expect(cursor2.getBufferPosition()).toEqual [3,47]
|
||||
|
||||
expect(editSession.getSelections().length).toBe 2
|
||||
[selection1, selection2] = editSession.getSelections()
|
||||
expect(selection1.getBufferRange()).toEqual [[0,4], [0,13]]
|
||||
expect(selection1.isReversed()).toBeTruthy()
|
||||
expect(selection2.getBufferRange()).toEqual [[3,44], [3,49]]
|
||||
expect(selection2.getBufferRange()).toEqual [[3,47], [3,49]]
|
||||
expect(selection2.isReversed()).toBeTruthy()
|
||||
|
||||
describe ".selectToEndOfWord()", ->
|
||||
@@ -553,40 +553,44 @@ describe "EditSession", ->
|
||||
expect(editSession.getCursors().length).toBe 2
|
||||
[cursor1, cursor2] = editSession.getCursors()
|
||||
expect(cursor1.getBufferPosition()).toEqual [0,13]
|
||||
expect(cursor2.getBufferPosition()).toEqual [3,51]
|
||||
expect(cursor2.getBufferPosition()).toEqual [3,50]
|
||||
|
||||
expect(editSession.getSelections().length).toBe 2
|
||||
[selection1, selection2] = editSession.getSelections()
|
||||
expect(selection1.getBufferRange()).toEqual [[0,4], [0,13]]
|
||||
expect(selection1.isReversed()).toBeFalsy()
|
||||
expect(selection2.getBufferRange()).toEqual [[3,48], [3,51]]
|
||||
expect(selection2.getBufferRange()).toEqual [[3,48], [3,50]]
|
||||
expect(selection2.isReversed()).toBeFalsy()
|
||||
|
||||
describe ".selectWord()", ->
|
||||
describe "when the cursor is inside a word", ->
|
||||
it "selects the entire word", ->
|
||||
editSession.setCursorScreenPosition([0, 8])
|
||||
editSession.selectWord()
|
||||
expect(editSession.getSelectedText()).toBe 'quicksort'
|
||||
describe "when the cursor is inside a word", ->
|
||||
it "selects the entire word", ->
|
||||
editSession.setCursorScreenPosition([0, 8])
|
||||
editSession.selectWord()
|
||||
expect(editSession.getSelectedText()).toBe 'quicksort'
|
||||
|
||||
describe "when the cursor is between two words", ->
|
||||
it "selects both words", ->
|
||||
editSession.setCursorScreenPosition([0, 4])
|
||||
editSession.selectWord()
|
||||
expect(editSession.getSelectedText()).toBe ' quicksort'
|
||||
describe "when the cursor is between two words", ->
|
||||
it "selects the nearest word", ->
|
||||
editSession.setCursorScreenPosition([0, 4])
|
||||
editSession.selectWord()
|
||||
expect(editSession.getSelectedText()).toBe 'quicksort'
|
||||
|
||||
describe "when the cursor is inside a region of whitespace", ->
|
||||
it "selects the whitespace region", ->
|
||||
editSession.setCursorScreenPosition([5, 2])
|
||||
editSession.selectWord()
|
||||
expect(editSession.getSelectedBufferRange()).toEqual [[5, 0], [5, 6]]
|
||||
describe "when the cursor is inside a region of whitespace", ->
|
||||
it "selects the whitespace region", ->
|
||||
editSession.setCursorScreenPosition([5, 2])
|
||||
editSession.selectWord()
|
||||
expect(editSession.getSelectedBufferRange()).toEqual [[5, 0], [5, 6]]
|
||||
|
||||
describe "when the cursor is at the end of the text", ->
|
||||
it "select the previous word", ->
|
||||
editSession.buffer.append 'word'
|
||||
editSession.moveCursorToBottom()
|
||||
editSession.selectWord()
|
||||
expect(editSession.getSelectedBufferRange()).toEqual [[12, 2], [12, 6]]
|
||||
editSession.setCursorScreenPosition([5, 0])
|
||||
editSession.selectWord()
|
||||
expect(editSession.getSelectedBufferRange()).toEqual [[5, 0], [5, 6]]
|
||||
|
||||
describe "when the cursor is at the end of the text", ->
|
||||
it "select the previous word", ->
|
||||
editSession.buffer.append 'word'
|
||||
editSession.moveCursorToBottom()
|
||||
editSession.selectWord()
|
||||
expect(editSession.getSelectedBufferRange()).toEqual [[12, 2], [12, 6]]
|
||||
|
||||
describe ".setSelectedBufferRanges(ranges)", ->
|
||||
it "clears existing selections and creates selections for each of the given ranges", ->
|
||||
@@ -1126,25 +1130,26 @@ describe "EditSession", ->
|
||||
describe "when no text is selected", ->
|
||||
it "deletes all text between the cursor and the beginning of the word", ->
|
||||
editSession.setCursorBufferPosition([1, 24])
|
||||
editSession.addCursorAtBufferPosition([2, 5])
|
||||
editSession.addCursorAtBufferPosition([3, 5])
|
||||
[cursor1, cursor2] = editSession.getCursors()
|
||||
|
||||
editSession.backspaceToBeginningOfWord()
|
||||
expect(buffer.lineForRow(1)).toBe ' var sort = function(ems) {'
|
||||
expect(buffer.lineForRow(2)).toBe ' f (items.length <= 1) return items;'
|
||||
expect(buffer.lineForRow(3)).toBe ' ar pivot = items.shift(), current, left = [], right = [];'
|
||||
expect(cursor1.getBufferPosition()).toEqual [1, 22]
|
||||
expect(cursor2.getBufferPosition()).toEqual [2, 4]
|
||||
expect(cursor2.getBufferPosition()).toEqual [3, 4]
|
||||
|
||||
editSession.backspaceToBeginningOfWord()
|
||||
expect(buffer.lineForRow(1)).toBe ' var sort = functionems) {'
|
||||
expect(buffer.lineForRow(2)).toBe 'f (items.length <= 1) return items;'
|
||||
expect(buffer.lineForRow(2)).toBe ' if (items.length <= 1) return itemsar pivot = items.shift(), current, left = [], right = [];'
|
||||
expect(cursor1.getBufferPosition()).toEqual [1, 21]
|
||||
expect(cursor2.getBufferPosition()).toEqual [2, 0]
|
||||
expect(cursor2.getBufferPosition()).toEqual [2, 39]
|
||||
|
||||
editSession.backspaceToBeginningOfWord()
|
||||
expect(buffer.lineForRow(1)).toBe ' var sort = emsf (items.length <= 1) return items;'
|
||||
expect(buffer.lineForRow(1)).toBe ' var sort = ems) {'
|
||||
expect(buffer.lineForRow(2)).toBe ' if (items.length <= 1) return ar pivot = items.shift(), current, left = [], right = [];'
|
||||
expect(cursor1.getBufferPosition()).toEqual [1, 13]
|
||||
expect(cursor2.getBufferPosition()).toEqual [1, 16]
|
||||
expect(cursor2.getBufferPosition()).toEqual [2, 34]
|
||||
|
||||
describe "when text is selected", ->
|
||||
it "deletes only selected text", ->
|
||||
@@ -1312,7 +1317,7 @@ describe "EditSession", ->
|
||||
expect(cursor2.getBufferPosition()).toEqual [2, 5]
|
||||
|
||||
editSession.deleteToEndOfWord()
|
||||
expect(buffer.lineForRow(1)).toBe ' var sort = function(it'
|
||||
expect(buffer.lineForRow(1)).toBe ' var sort = function(it {'
|
||||
expect(buffer.lineForRow(2)).toBe ' iitems.length <= 1) return items;'
|
||||
expect(cursor1.getBufferPosition()).toEqual [1, 24]
|
||||
expect(cursor2.getBufferPosition()).toEqual [2, 5]
|
||||
|
||||
Reference in New Issue
Block a user