From b4654ea4355af3877cc9dc614cfd4e6a0706c621 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 7 Jan 2013 11:29:50 -0800 Subject: [PATCH] Use buffer position when end of word isn't found Previously if null was returned for the end of word position then it was interpreted as 0,0 which would select the entire contents before the current word instead of the current word. --- spec/app/edit-session-spec.coffee | 7 +++++++ src/app/cursor.coffee | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index cf6ab48a5..a06ac7ff2 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -529,6 +529,13 @@ describe "EditSession", -> editSession.selectWord() expect(editSession.getSelectedBufferRange()).toEqual [[5, 0], [5, 6]] + describe "when the cursor is at the end of the text", -> + it "select the previous word", -> + editSession.buffer.append 'word' + editSession.moveCursorToBottom() + editSession.selectWord() + expect(editSession.getSelectedBufferRange()).toEqual [[12, 2], [12, 6]] + describe ".setSelectedBufferRanges(ranges)", -> it "clears existing selections and creates selections for each of the given ranges", -> editSession.setSelectedBufferRanges([[[2, 2], [3, 3]], [[4, 4], [5, 5]]]) diff --git a/src/app/cursor.coffee b/src/app/cursor.coffee index 2a0a9b60c..ae0801239 100644 --- a/src/app/cursor.coffee +++ b/src/app/cursor.coffee @@ -167,7 +167,7 @@ class Cursor if not allowNext and matchRange.start.isGreaterThan(currentBufferPosition) endOfWordPosition = currentBufferPosition stop() - endOfWordPosition + endOfWordPosition or currentBufferPosition getCurrentWordBufferRange: -> new Range(@getBeginningOfCurrentWordBufferPosition(allowPrevious: false), @getEndOfCurrentWordBufferPosition(allowNext: false))