Add Cursor::moveToNextWordBoundry()

Plumb up to editor as well.
This commit is contained in:
Ben Ogle
2013-07-19 11:37:47 -07:00
parent ab8df8dcde
commit 13b592d1f3
4 changed files with 49 additions and 1 deletions

View File

@@ -249,6 +249,11 @@ class Cursor
if position = @getMovePreviousWordBoundryBufferPosition()
@setBufferPosition(position)
# Moves the cursor to the next word boundry.
moveToNextWordBoundry: ->
if position = @getMoveNextWordBoundryBufferPosition()
@setBufferPosition(position)
# Retrieves the buffer position of where the current word starts.
#
# options - A hash with one option:
@@ -292,6 +297,27 @@ class Cursor
beginningOfWordPosition or currentBufferPosition
# Retrieves buffer position of previous word boiundry. It might be on the
# current word, or the previous word.
getMoveNextWordBoundryBufferPosition: (options = {}) ->
currentBufferPosition = @getBufferPosition()
scanRange = [currentBufferPosition, @editSession.getEofBufferPosition()]
endOfWordPosition = null
@editSession.scanInBufferRange (options.wordRegex ? @wordRegExp()), scanRange, ({range, stop}) =>
if range.start.row > currentBufferPosition.row # and currentBufferPosition.column > 0
# force it to stop at the beginning of each line
endOfWordPosition = new Point(range.start.row, 0)
else if range.start.isGreaterThan(currentBufferPosition)
endOfWordPosition = range.start
else
endOfWordPosition = range.end
if not endOfWordPosition?.isEqual(currentBufferPosition)
stop()
endOfWordPosition or currentBufferPosition
# Retrieves the buffer position of where the current word ends.
#
# options - A hash with one option:

View File

@@ -1104,6 +1104,9 @@ class EditSession
moveCursorToPreviousWordBoundry: ->
@moveCursors (cursor) -> cursor.moveToPreviousWordBoundry()
moveCursorToNextWordBoundry: ->
@moveCursors (cursor) -> cursor.moveToNextWordBoundry()
# Internal:
moveCursors: (fn) ->
fn(cursor) for cursor in @getCursors()

View File

@@ -142,6 +142,7 @@ class Editor extends View
'editor:move-to-end-of-word': @moveCursorToEndOfWord
'editor:move-to-beginning-of-next-word': @moveCursorToBeginningOfNextWord
'editor:move-to-previous-word-boundry': @moveCursorToPreviousWordBoundry
'editor:move-to-next-word-boundry': @moveCursorToNextWordBoundry
'editor:select-to-end-of-line': @selectToEndOfLine
'editor:select-to-beginning-of-line': @selectToBeginningOfLine
'editor:select-to-end-of-word': @selectToEndOfWord
@@ -241,6 +242,9 @@ class Editor extends View
# {Delegates to: EditSession.moveCursorToPreviousWordBoundry}
moveCursorToPreviousWordBoundry: -> @activeEditSession.moveCursorToPreviousWordBoundry()
# {Delegates to: EditSession.moveCursorToNextWordBoundry}
moveCursorToNextWordBoundry: -> @activeEditSession.moveCursorToNextWordBoundry()
# {Delegates to: EditSession.moveCursorToEndOfLine}
moveCursorToEndOfLine: -> @activeEditSession.moveCursorToEndOfLine()