Specs for moveCursorToBeginningOfNextWord

This commit is contained in:
Mutwin Kraus
2013-04-08 14:15:25 +02:00
parent a12c78100e
commit 2445829f83
5 changed files with 56 additions and 2 deletions

View File

@@ -341,6 +341,35 @@ describe "EditSession", ->
editSession.moveCursorToEndOfWord()
expect(editSession.getCursorBufferPosition()).toEqual [11, 8]
describe ".moveCursorToBeginningOfNextWord()", ->
it "moves the cursor before the first character of the next word", ->
editSession.setCursorBufferPosition [0,6]
editSession.addCursorAtBufferPosition [1,11]
editSession.addCursorAtBufferPosition [2,0]
[cursor1, cursor2, cursor3] = editSession.getCursors()
editSession.moveCursorToBeginningOfNextWord()
expect(cursor1.getBufferPosition()).toEqual [0, 14]
expect(cursor2.getBufferPosition()).toEqual [1, 13]
expect(cursor3.getBufferPosition()).toEqual [2, 4]
it "does not blow up when there is no next word", ->
editSession.setCursorBufferPosition [Infinity, Infinity]
endPosition = editSession.getCursorBufferPosition()
editSession.moveCursorToBeginningOfNextWord()
expect(editSession.getCursorBufferPosition()).toEqual endPosition
it "treats lines with only whitespace as a word", ->
editSession.setCursorBufferPosition([9, 4])
editSession.moveCursorToBeginningOfNextWord()
expect(editSession.getCursorBufferPosition()).toEqual [10, 0]
it "works when the current line is blank", ->
editSession.setCursorBufferPosition([10, 0])
editSession.moveCursorToBeginningOfNextWord()
expect(editSession.getCursorBufferPosition()).toEqual [11, 9]
describe ".getCurrentParagraphBufferRange()", ->
it "returns the buffer range of the current paragraph, delimited by blank lines or the beginning / end of the file", ->
buffer.setText """

View File

@@ -165,6 +165,10 @@ class Cursor
if position = @getEndOfCurrentWordBufferPosition()
@setBufferPosition(position)
moveToBeginningOfNextWord: ->
if position = @getBeginningOfNextWordBufferPosition()
@setBufferPosition(position)
getBeginningOfCurrentWordBufferPosition: (options = {}) ->
allowPrevious = options.allowPrevious ? true
currentBufferPosition = @getBufferPosition()
@@ -194,6 +198,18 @@ class Cursor
endOfWordPosition or currentBufferPosition
getBeginningOfNextWordBufferPosition: (options = {}) ->
currentBufferPosition = @getBufferPosition()
start = if @isSurroundedByWhitespace() then currentBufferPosition else @getEndOfCurrentWordBufferPosition()
scanRange = [start, @editSession.getEofBufferPosition()]
beginningOfNextWordPosition = null
@editSession.scanInBufferRange (options.wordRegex ? @wordRegExp()), scanRange, ({range, stop}) =>
beginningOfNextWordPosition = range.start
stop()
beginningOfNextWordPosition or currentBufferPosition
getCurrentWordBufferRange: (options={}) ->
startOptions = _.extend(_.clone(options), allowPrevious: false)
endOptions = _.extend(_.clone(options), allowNext: false)

View File

@@ -728,6 +728,9 @@ class EditSession
moveCursorToEndOfWord: ->
@moveCursors (cursor) -> cursor.moveToEndOfWord()
moveCursorToBeginningOfNextWord: ->
@moveCursors (cursor) -> cursor.moveToBeginningOfNextWord()
moveCursors: (fn) ->
fn(cursor) for cursor in @getCursors()
@mergeCursors()
@@ -802,6 +805,9 @@ class EditSession
selectToEndOfWord: ->
@expandSelectionsForward (selection) => selection.selectToEndOfWord()
selectToBeginningOfNextWord: ->
@expandSelectionsForward (selection) => selection.selectToBeginningOfNextWord()
selectWord: ->
@expandSelectionsForward (selection) => selection.selectWord()

View File

@@ -180,7 +180,7 @@ class Editor extends View
moveCursorRight: -> @activeEditSession.moveCursorRight()
moveCursorToBeginningOfWord: -> @activeEditSession.moveCursorToBeginningOfWord()
moveCursorToEndOfWord: -> @activeEditSession.moveCursorToEndOfWord()
moveCursorToBeginningOfNextWord: -> @activeEditSession.moveCursorToEndOfWord(); @activeEditSession.moveCursorRight()
moveCursorToBeginningOfNextWord: -> @activeEditSession.moveCursorToBeginningOfNextWord()
moveCursorToTop: -> @activeEditSession.moveCursorToTop()
moveCursorToBottom: -> @activeEditSession.moveCursorToBottom()
moveCursorToBeginningOfLine: -> @activeEditSession.moveCursorToBeginningOfLine()
@@ -221,7 +221,7 @@ class Editor extends View
addSelectionAbove: -> @activeEditSession.addSelectionAbove()
selectToBeginningOfWord: -> @activeEditSession.selectToBeginningOfWord()
selectToEndOfWord: -> @activeEditSession.selectToEndOfWord()
selectToBeginningOfNextWord: -> @activeEditSession.selectToEndOfWord(); @activeEditSession.selectRight()
selectToBeginningOfNextWord: -> @activeEditSession.selectBeginningOfNextWord()
selectWord: -> @activeEditSession.selectWord()
selectLine: -> @activeEditSession.selectLine()
selectToScreenPosition: (position) -> @activeEditSession.selectToScreenPosition(position)

View File

@@ -152,6 +152,9 @@ class Selection
selectToEndOfWord: ->
@modifySelection => @cursor.moveToEndOfWord()
selectToBeginningOfNextWord: ->
@modifySelection => @cursor.moveToBeginningOfNextWord()
addSelectionBelow: ->
range = (@goalBufferRange ? @getBufferRange()).copy()
nextRow = range.end.row + 1