mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
Add Cursor::moveToNextWordBoundry()
Plumb up to editor as well.
This commit is contained in:
@@ -313,7 +313,7 @@ describe "EditSession", ->
|
||||
editSession.moveCursorToBeginningOfWord()
|
||||
expect(editSession.getCursorBufferPosition()).toEqual [9, 2]
|
||||
|
||||
fdescribe ".moveCursorToPreviousWordBoundry()", ->
|
||||
describe ".moveCursorToPreviousWordBoundry()", ->
|
||||
it "moves the cursor to the previous word boundry", ->
|
||||
editSession.setCursorBufferPosition [0, 8]
|
||||
editSession.addCursorAtBufferPosition [2, 0]
|
||||
@@ -328,6 +328,21 @@ describe "EditSession", ->
|
||||
expect(cursor3.getBufferPosition()).toEqual [2, 0]
|
||||
expect(cursor4.getBufferPosition()).toEqual [3, 13]
|
||||
|
||||
describe ".moveCursorToNextWordBoundry()", ->
|
||||
it "moves the cursor to the previous word boundry", ->
|
||||
editSession.setCursorBufferPosition [0, 8]
|
||||
editSession.addCursorAtBufferPosition [2, 40]
|
||||
editSession.addCursorAtBufferPosition [3, 0]
|
||||
editSession.addCursorAtBufferPosition [3, 30]
|
||||
[cursor1, cursor2, cursor3, cursor4] = editSession.getCursors()
|
||||
|
||||
editSession.moveCursorToNextWordBoundry()
|
||||
|
||||
expect(cursor1.getBufferPosition()).toEqual [0, 13]
|
||||
expect(cursor2.getBufferPosition()).toEqual [3, 0]
|
||||
expect(cursor3.getBufferPosition()).toEqual [3, 4]
|
||||
expect(cursor4.getBufferPosition()).toEqual [3, 31]
|
||||
|
||||
describe ".moveCursorToEndOfWord()", ->
|
||||
it "moves the cursor to the end of the word", ->
|
||||
editSession.setCursorBufferPosition [0, 6]
|
||||
|
||||
@@ -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