mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Cursor.moveCursorToBeginningOfNextWord() behaves correctly on whitespace
Closes #669
This commit is contained in:
@@ -427,6 +427,14 @@ describe "EditSession", ->
|
||||
expect(cursor2.getBufferPosition()).toEqual [1, 13]
|
||||
expect(cursor3.getBufferPosition()).toEqual [2, 4]
|
||||
|
||||
# When the cursor is on whitespace
|
||||
editSession.setText("ab cde- ")
|
||||
editSession.setCursorBufferPosition [0,2]
|
||||
cursor = editSession.getCursor()
|
||||
editSession.moveCursorToBeginningOfNextWord()
|
||||
|
||||
expect(cursor.getBufferPosition()).toEqual [0, 3]
|
||||
|
||||
it "does not blow up when there is no next word", ->
|
||||
editSession.setCursorBufferPosition [Infinity, Infinity]
|
||||
endPosition = editSession.getCursorBufferPosition()
|
||||
|
||||
@@ -128,6 +128,11 @@ class Cursor
|
||||
range = [[row, Math.min(0, column - 1)], [row, Math.max(0, column + 1)]]
|
||||
/^\s+$/.test @editSession.getTextInBufferRange(range)
|
||||
|
||||
isInsideWord: ->
|
||||
{row, column} = @getBufferPosition()
|
||||
range = [[row, column], [row, Infinity]]
|
||||
@editSession.getTextInBufferRange(range).search(@wordRegExp()) == 0
|
||||
|
||||
# Removes the setting for auto-scroll.
|
||||
clearAutoscroll: ->
|
||||
@needsAutoscroll = null
|
||||
@@ -370,7 +375,7 @@ class Cursor
|
||||
# Returns a {Range}.
|
||||
getBeginningOfNextWordBufferPosition: (options = {}) ->
|
||||
currentBufferPosition = @getBufferPosition()
|
||||
start = if @isSurroundedByWhitespace() then currentBufferPosition else @getEndOfCurrentWordBufferPosition()
|
||||
start = if @isInsideWord() then @getEndOfCurrentWordBufferPosition() else currentBufferPosition
|
||||
scanRange = [start, @editSession.getEofBufferPosition()]
|
||||
|
||||
beginningOfNextWordPosition = null
|
||||
|
||||
Reference in New Issue
Block a user