From bf9a7cc9a1d87e71ea7a2c94ea68004c466abdec Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Mon, 26 Nov 2012 15:12:21 -0700 Subject: [PATCH] Fix exception when moving to the end of word when there *is* no word --- spec/app/edit-session-spec.coffee | 6 ++++++ src/app/cursor.coffee | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index cdbb394b3..dd0a6c3f1 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -296,6 +296,12 @@ describe "EditSession", -> expect(cursor2.getBufferPosition()).toEqual [1, 13] expect(cursor3.getBufferPosition()).toEqual [3, 4] + it "does not blow up when there is no next word", -> + editSession.setCursorBufferPosition [Infinity, Infinity] + endPosition = editSession.getCursorBufferPosition() + editSession.moveCursorToEndOfWord() + expect(editSession.getCursorBufferPosition()).toEqual endPosition + describe "selection", -> selection = null diff --git a/src/app/cursor.coffee b/src/app/cursor.coffee index fa1debab2..4fe6896cf 100644 --- a/src/app/cursor.coffee +++ b/src/app/cursor.coffee @@ -130,7 +130,8 @@ class Cursor @setBufferPosition(@getBeginningOfCurrentWordBufferPosition()) moveToEndOfWord: -> - @setBufferPosition(@getEndOfCurrentWordBufferPosition()) + if position = @getEndOfCurrentWordBufferPosition() + @setBufferPosition(position) getBeginningOfCurrentWordBufferPosition: (options = {}) -> allowPrevious = options.allowPrevious ? true