Bugfix: move-to-beginning-of-word no longer raises an error at position [0, 0]

This commit is contained in:
Nathan Sobo
2012-04-09 13:59:46 -06:00
parent f3372f08de
commit cc52ff6f28
2 changed files with 10 additions and 7 deletions

View File

@@ -417,6 +417,10 @@ describe "Editor", ->
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]

View File

@@ -101,15 +101,14 @@ class Cursor extends View
getBeginningOfCurrentWordBufferPosition: (options = {}) ->
allowPrevious = options.allowPrevious ? true
position = null
bufferPosition = @getBufferPosition()
range = [[0,0], bufferPosition]
currentBufferPosition = @getBufferPosition()
beginningOfWordPosition = currentBufferPosition
range = [[0,0], currentBufferPosition]
@editor.backwardsTraverseRegexMatchesInRange @wordRegex, range, (match, matchRange, { stop }) =>
position = matchRange.start
if not allowPrevious and matchRange.end.isLessThan(bufferPosition)
position = bufferPosition
if matchRange.end.isGreaterThanOrEqual(currentBufferPosition) or allowPrevious
beginningOfWordPosition = matchRange.start
stop()
position
beginningOfWordPosition
getEndOfCurrentWordBufferPosition: (options = {}) ->
allowNext = options.allowNext ? true