diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index 6f72cd8bc..a16554f84 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -16,7 +16,7 @@ describe "EditSession", -> afterEach -> fixturesProject.destroy() - describe "cursor", -> + fdescribe "cursor", -> describe ".getCursor()", -> it "returns the most recently created cursor", -> editSession.addCursorAtScreenPosition([1, 0]) @@ -276,17 +276,17 @@ describe "EditSession", -> editSession.moveCursorToBeginningOfWord() expect(cursor1.getBufferPosition()).toEqual [0, 4] - expect(cursor2.getBufferPosition()).toEqual [1, 10] + expect(cursor2.getBufferPosition()).toEqual [1, 11] expect(cursor3.getBufferPosition()).toEqual [2, 39] it "does not fail at position [0, 0]", -> editSession.setCursorBufferPosition([0, 0]) editSession.moveCursorToBeginningOfWord() - it "works when the preceding line is blank", -> - editSession.setCursorBufferPosition([10, 0]) + it "works when the previous line is blank", -> + editSession.setCursorBufferPosition([11, 0]) editSession.moveCursorToBeginningOfWord() - expect(editSession.getCursorBufferPosition()).toEqual [9, 0] + expect(editSession.getCursorBufferPosition()).toEqual [10, 0] describe ".moveCursorToEndOfWord()", -> it "moves the cursor to the end of the word", -> diff --git a/src/app/cursor.coffee b/src/app/cursor.coffee index efc80fbf4..cc4c13c30 100644 --- a/src/app/cursor.coffee +++ b/src/app/cursor.coffee @@ -149,10 +149,14 @@ class Cursor previousLinesRange = [[previousNonBlankRow, 0], currentBufferPosition] beginningOfWordPosition = currentBufferPosition - @editSession.backwardsScanInRange (options.wordRegex ? config.get("editor.wordRegex")), previousLinesRange, (match, matchRange, { stop }) => + + wordSeparators = config.get("editor.wordSeparators") + wordSeparatorsRegex = new RegExp("^[\t ]*\n|[^\\s#{_.escapeRegExp(wordSeparators)}]+|[#{_.escapeRegExp(wordSeparators)}]+", "m") + @editSession.backwardsScanInRange (options.wordRegex ? wordSeparatorsRegex), previousLinesRange, (match, matchRange, { stop }) => if matchRange.end.isGreaterThanOrEqual(currentBufferPosition) or allowPrevious beginningOfWordPosition = matchRange.start stop() + beginningOfWordPosition getEndOfCurrentWordBufferPosition: (options = {}) -> diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 55600c0fa..affeefc68 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -20,6 +20,7 @@ class Editor extends View autoIndent: true autoIndentOnPaste: false wordRegex: /(\w+)|([^\w\n]+)/g + wordSeparators: "./\()\"’-:,.;<>~!@#$%^&*|+=[]{}`~?" @content: (params) -> @div class: @classes(params), tabindex: -1, =>