end/beginning word implementations are now more similar

This commit is contained in:
Corey Johnson
2013-01-30 08:39:32 -08:00
parent f698d7e9dc
commit 97fa9d522a
2 changed files with 9 additions and 5 deletions

View File

@@ -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])

View File

@@ -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