mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
cursor.getBeginningOfCurrentWordBufferPosition behaves like vim
This commit is contained in:
@@ -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", ->
|
||||
|
||||
@@ -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 = {}) ->
|
||||
|
||||
@@ -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, =>
|
||||
|
||||
Reference in New Issue
Block a user