mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Add Cursor::moveToNextWordBoundry()
Plumb up to editor as well.
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user