diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index 7c5961161..7fc300fa2 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -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] diff --git a/src/app/cursor.coffee b/src/app/cursor.coffee index 54e2921df..1af6770dc 100644 --- a/src/app/cursor.coffee +++ b/src/app/cursor.coffee @@ -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: diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index dbb4f9d61..0e0dbe533 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -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() diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 6e01f3c69..70e0c9d49 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -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()