Cursor.moveCursorToBeginningOfNextWord() behaves correctly on whitespace

Closes #669
This commit is contained in:
probablycorey
2013-08-05 16:46:31 -07:00
parent 557ada7c81
commit c38edbfe0b
2 changed files with 14 additions and 1 deletions

View File

@@ -427,6 +427,14 @@ describe "EditSession", ->
expect(cursor2.getBufferPosition()).toEqual [1, 13]
expect(cursor3.getBufferPosition()).toEqual [2, 4]
# When the cursor is on whitespace
editSession.setText("ab cde- ")
editSession.setCursorBufferPosition [0,2]
cursor = editSession.getCursor()
editSession.moveCursorToBeginningOfNextWord()
expect(cursor.getBufferPosition()).toEqual [0, 3]
it "does not blow up when there is no next word", ->
editSession.setCursorBufferPosition [Infinity, Infinity]
endPosition = editSession.getCursorBufferPosition()

View File

@@ -128,6 +128,11 @@ class Cursor
range = [[row, Math.min(0, column - 1)], [row, Math.max(0, column + 1)]]
/^\s+$/.test @editSession.getTextInBufferRange(range)
isInsideWord: ->
{row, column} = @getBufferPosition()
range = [[row, column], [row, Infinity]]
@editSession.getTextInBufferRange(range).search(@wordRegExp()) == 0
# Removes the setting for auto-scroll.
clearAutoscroll: ->
@needsAutoscroll = null
@@ -370,7 +375,7 @@ class Cursor
# Returns a {Range}.
getBeginningOfNextWordBufferPosition: (options = {}) ->
currentBufferPosition = @getBufferPosition()
start = if @isSurroundedByWhitespace() then currentBufferPosition else @getEndOfCurrentWordBufferPosition()
start = if @isInsideWord() then @getEndOfCurrentWordBufferPosition() else currentBufferPosition
scanRange = [start, @editSession.getEofBufferPosition()]
beginningOfNextWordPosition = null