From e2daef477cf261a03b36c91ae1c022106f16efab Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 27 Sep 2013 15:27:11 -0700 Subject: [PATCH] Return false if either character is whitespace --- spec/editor-spec.coffee | 7 +++++++ src/cursor.coffee | 12 +++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/spec/editor-spec.coffee b/spec/editor-spec.coffee index 5eb3cc84e..afb7bf8c8 100644 --- a/spec/editor-spec.coffee +++ b/spec/editor-spec.coffee @@ -456,6 +456,13 @@ describe "Editor", -> editor.renderedLines.trigger 'mouseup' expect(editor.getSelectedText()).toBe "items" + editor.setCursorBufferPosition([0, 0]) + editor.renderedLines.trigger mousedownEvent(editor: editor, point: [0, 28], originalEvent: {detail: 1}) + editor.renderedLines.trigger 'mouseup' + editor.renderedLines.trigger mousedownEvent(editor: editor, point: [0, 28], originalEvent: {detail: 2}) + editor.renderedLines.trigger 'mouseup' + expect(editor.getSelectedText()).toBe "{" + describe "triple/quardruple/etc-click", -> it "selects the line under the cursor", -> expect(editor.getCursorScreenPosition()).toEqual(row: 0, column: 0) diff --git a/src/cursor.coffee b/src/cursor.coffee index 621a6f1b4..0b3941f22 100644 --- a/src/cursor.coffee +++ b/src/cursor.coffee @@ -141,6 +141,9 @@ class Cursor # character. The non-word characters are defined by the # `editor.nonWordCharacters` config value. # + # This method returns false if the character before or after the cursor is + # whitespace. + # # Returns a Boolean. isBetweenWordAndNonWord: -> return false if @isAtBeginningOfLine() or @isAtEndOfLine() @@ -148,11 +151,10 @@ class Cursor {row, column} = @getBufferPosition() range = [[row, column - 1], [row, column + 1]] [before, after] = @editSession.getTextInBufferRange(range) - if before and after - nonWordCharacters = config.get('editor.nonWordCharacters').split('') - _.contains(nonWordCharacters, before) isnt _.contains(nonWordCharacters, after) - else - false + return false if /\s/.test(before) or /\s/.test(after) + + nonWordCharacters = config.get('editor.nonWordCharacters').split('') + _.contains(nonWordCharacters, before) isnt _.contains(nonWordCharacters, after) # Public: Returns whether this cursor is between a word's start and end. isInsideWord: ->