From c02df26fa7bf4bf27eaa14b28f5746c887adee76 Mon Sep 17 00:00:00 2001 From: Darrell Sandstrom Date: Sun, 12 Jul 2015 17:03:53 -0700 Subject: [PATCH] Add underscore to subword regex Fixes #7658 --- spec/text-editor-spec.coffee | 18 ++++++++++++------ src/cursor.coffee | 8 +++++--- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/spec/text-editor-spec.coffee b/spec/text-editor-spec.coffee index 7a0803ac7..f0b463ca3 100644 --- a/spec/text-editor-spec.coffee +++ b/spec/text-editor-spec.coffee @@ -4450,13 +4450,16 @@ describe "TextEditor", -> expect(editor.getCursorBufferPosition()).toEqual([0, 0]) it "stops at word and underscore boundaries", -> - editor.setText("_word \n") - editor.setCursorBufferPosition([0, 6]) + editor.setText("sub_word \n") + editor.setCursorBufferPosition([0, 9]) editor.moveToPreviousSubwordBoundary() - expect(editor.getCursorBufferPosition()).toEqual([0, 5]) + expect(editor.getCursorBufferPosition()).toEqual([0, 8]) editor.moveToPreviousSubwordBoundary() - expect(editor.getCursorBufferPosition()).toEqual([0, 1]) + expect(editor.getCursorBufferPosition()).toEqual([0, 4]) + + editor.moveToPreviousSubwordBoundary() + expect(editor.getCursorBufferPosition()).toEqual([0, 0]) editor.setText(" word\n") editor.setCursorBufferPosition([0, 3]) @@ -4526,13 +4529,16 @@ describe "TextEditor", -> expect(editor.getCursorBufferPosition()).toEqual([0, 0]) it "stops at word and underscore boundaries", -> - editor.setText(" word_ \n") + editor.setText(" sub_word \n") editor.setCursorBufferPosition([0, 0]) editor.moveToNextSubwordBoundary() expect(editor.getCursorBufferPosition()).toEqual([0, 1]) editor.moveToNextSubwordBoundary() - expect(editor.getCursorBufferPosition()).toEqual([0, 5]) + expect(editor.getCursorBufferPosition()).toEqual([0, 4]) + + editor.moveToNextSubwordBoundary() + expect(editor.getCursorBufferPosition()).toEqual([0, 9]) editor.setText("word \n") editor.setCursorBufferPosition([0, 0]) diff --git a/src/cursor.coffee b/src/cursor.coffee index 61f12cc8c..57cf2b7b8 100644 --- a/src/cursor.coffee +++ b/src/cursor.coffee @@ -657,18 +657,20 @@ class Cursor extends Model # Returns a {RegExp}. subwordRegExp: (options={}) -> nonWordCharacters = atom.config.get('editor.nonWordCharacters', scope: @getScopeDescriptor()) + snakeCamelSegment = "[A-Z]?[a-z]+" segments = [ "^[\t ]+", "[\t ]+$", - "[A-Z]?[a-z]+", "[A-Z]+(?![a-z])", - "\\d+", - "_+" + "\\d+" ] if options.backwards + segments.push("#{snakeCamelSegment}_*") segments.push("[#{_.escapeRegExp(nonWordCharacters)}]+\\s*") else + segments.push("_*#{snakeCamelSegment}") segments.push("\\s*[#{_.escapeRegExp(nonWordCharacters)}]+") + segments.push("_+") new RegExp(segments.join("|"), "g") ###