diff --git a/lib/motions/general-motions.coffee b/lib/motions/general-motions.coffee index 7bbbf827..d88d154c 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) 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)