diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index 522e4372e..d9fe55c03 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -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] diff --git a/src/app/cursor.coffee b/src/app/cursor.coffee index 01f145623..47cbefe16 100644 --- a/src/app/cursor.coffee +++ b/src/app/cursor.coffee @@ -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