From 6f061731c62f982fee464322b3f03facd7f8804a Mon Sep 17 00:00:00 2001 From: Darrell Sandstrom Date: Sat, 14 Mar 2015 12:46:59 -0700 Subject: [PATCH 1/2] Add new word regex for MoveToNextWord --- lib/motions/general-motions.coffee | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/motions/general-motions.coffee b/lib/motions/general-motions.coffee index 7bbbf827..7a3c6cd3 100644 --- a/lib/motions/general-motions.coffee +++ b/lib/motions/general-motions.coffee @@ -201,7 +201,18 @@ class MoveToNextWord extends Motion wordRegex: null operatesInclusively: false + wordRegExp: (cursor, {includeNonWordCharacters}={}) -> + includeNonWordCharacters ?= true + nonWordCharacters = atom.config.get('editor.nonWordCharacters', scope: cursor.getScopeDescriptor()) + segments = ["^[\t ]*$"] + segments.push("[^\\s#{_.escapeRegExp(nonWordCharacters)}]+") + segments.push("$") + if includeNonWordCharacters + segments.push("[#{_.escapeRegExp(nonWordCharacters)}]+") + new RegExp(segments.join("|"), "g") + moveCursor: (cursor, count=1, options) -> + @wordRegex = @wordRegExp(cursor) _.times count, => current = cursor.getBufferPosition() From 34654ee4760391eb9b9531c4a3dab357d16bb15c Mon Sep 17 00:00:00 2001 From: Darrell Sandstrom Date: Sat, 14 Mar 2015 13:53:23 -0700 Subject: [PATCH 2/2] Only use regex when deleting, fix test --- lib/motions/general-motions.coffee | 2 +- lib/operators/general-operators.coffee | 1 + spec/operators-spec.coffee | 7 ++++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/motions/general-motions.coffee b/lib/motions/general-motions.coffee index 7a3c6cd3..d88d154c 100644 --- a/lib/motions/general-motions.coffee +++ b/lib/motions/general-motions.coffee @@ -212,7 +212,7 @@ class MoveToNextWord extends Motion new RegExp(segments.join("|"), "g") moveCursor: (cursor, count=1, options) -> - @wordRegex = @wordRegExp(cursor) + @wordRegex = @wordRegExp(cursor) if options?.allowEOL _.times count, => current = cursor.getBufferPosition() diff --git a/lib/operators/general-operators.coffee b/lib/operators/general-operators.coffee index 0d29af83..a85f98e3 100644 --- a/lib/operators/general-operators.coffee +++ b/lib/operators/general-operators.coffee @@ -84,6 +84,7 @@ class Delete extends Operator @complete = false @selectOptions ?= {} @selectOptions.requireEOL ?= true + @selectOptions.allowEOL ?= true @register = settings.defaultRegister() # Public: Deletes the text selected by the given motion. diff --git a/spec/operators-spec.coffee b/spec/operators-spec.coffee index 25ef2e5b..43c208c6 100644 --- a/spec/operators-spec.coffee +++ b/spec/operators-spec.coffee @@ -240,9 +240,10 @@ describe "Operators", -> keydown('w') # Incompatibility with VIM. In vim, `w` behaves differently as an - # operator than as a motion; it stops at the end of a line.expect(editor.getText()).toBe "abcd abc" - expect(editor.getText()).toBe "abcd abc" - expect(editor.getCursorScreenPosition()).toEqual [0, 5] + # operator than as a motion; it stops at the end of a line + # and removes the preceding space: `expect(editor.getText()).toBe "abcd\nabc"` + expect(editor.getText()).toBe "abcd \nabc" + expect(editor.getCursorScreenPosition()).toEqual [0, 4] expect(editorElement.classList.contains('operator-pending-mode')).toBe(false) expect(editorElement.classList.contains('command-mode')).toBe(true)