cursor.getBeginningOfCurrentWordBufferPosition behaves like vim

This commit is contained in:
Corey Johnson
2013-01-29 11:08:17 -08:00
parent 1d2fa089e5
commit b66efbe3e7
3 changed files with 11 additions and 6 deletions

View File

@@ -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", ->

View File

@@ -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 = {}) ->

View File

@@ -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, =>