diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index 327f6ab76..c77ddd15c 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -570,11 +570,16 @@ describe "EditSession", -> expect(editSession.getSelectedText()).toBe 'quicksort' describe "when the cursor is between two words", -> - it "selects the nearest word", -> + it "selects the word the cursor is on", -> editSession.setCursorScreenPosition([0, 4]) editSession.selectWord() expect(editSession.getSelectedText()).toBe 'quicksort' + editSession.setCursorScreenPosition([0, 3]) + editSession.selectWord() + expect(editSession.getSelectedText()).toBe 'var' + + describe "when the cursor is inside a region of whitespace", -> it "selects the whitespace region", -> editSession.setCursorScreenPosition([5, 2]) diff --git a/src/app/cursor.coffee b/src/app/cursor.coffee index 659e91e43..8ac44739e 100644 --- a/src/app/cursor.coffee +++ b/src/app/cursor.coffee @@ -173,10 +173,9 @@ class Cursor endOfWordPosition = null @editSession.scanInRange (options.wordRegex ? @wordRegExp()), range, (match, matchRange, { stop }) => - endOfWordPosition = matchRange.end - if matchRange.start.isGreaterThan(currentBufferPosition) and not allowNext - endOfWordPosition = currentBufferPosition - if not endOfWordPosition.isEqual(currentBufferPosition) + if matchRange.start.isLessThanOrEqual(currentBufferPosition) or allowNext + endOfWordPosition = matchRange.end + if not endOfWordPosition?.isEqual(currentBufferPosition) stop() endOfWordPosition or currentBufferPosition