mirror of
https://github.com/atom/atom.git
synced 2026-02-09 14:15:24 -05:00
Add move-to-end-of-word and move-to-beginning-of-word.
Buffer.traverseRegexMatchesInRange matches text that at end of range, even if the match could have exceeded end of the range.
This commit is contained in:
@@ -154,9 +154,15 @@ class Buffer
|
||||
|
||||
matchLength = match[0].length
|
||||
matchStartIndex = match.index
|
||||
matchEndIndex = match.index + matchLength
|
||||
matchEndIndex = matchStartIndex + matchLength
|
||||
|
||||
return if matchEndIndex > endIndex
|
||||
if matchEndIndex > endIndex
|
||||
regex.lastIndex = 0
|
||||
if matchStartIndex < endIndex and match = regex.exec(text[matchStartIndex..endIndex])
|
||||
matchLength = match[0].length
|
||||
matchEndIndex = matchStartIndex + matchLength
|
||||
else
|
||||
return
|
||||
|
||||
startPosition = @positionForCharacterIndex(matchStartIndex + lengthDelta)
|
||||
endPosition = @positionForCharacterIndex(matchEndIndex + lengthDelta)
|
||||
|
||||
@@ -60,8 +60,11 @@ class CompositeCursor
|
||||
moveToNextWord: ->
|
||||
@modifyCursors (cursor) -> cursor.moveToNextWord()
|
||||
|
||||
moveToPreviousWord: ->
|
||||
@modifyCursors (cursor) -> cursor.moveToPreviousWord()
|
||||
moveToBeginningOfWord: ->
|
||||
@modifyCursors (cursor) -> cursor.moveToBeginningOfWord()
|
||||
|
||||
moveToEndOfWord: ->
|
||||
@modifyCursors (cursor) -> cursor.moveToEndOfWord()
|
||||
|
||||
moveToTop: ->
|
||||
@modifyCursors (cursor) -> cursor.moveToTop()
|
||||
|
||||
@@ -117,16 +117,20 @@ class Cursor extends View
|
||||
|
||||
@setBufferPosition(nextPosition or @editor.getEofPosition())
|
||||
|
||||
moveToPreviousWord: ->
|
||||
moveToBeginningOfWord: ->
|
||||
bufferPosition = @getBufferPosition()
|
||||
range = [[0, 0], bufferPosition]
|
||||
|
||||
nextPosition = null
|
||||
range = [[0,0], bufferPosition]
|
||||
@editor.backwardsTraverseRegexMatchesInRange @wordRegex, range, (match, matchRange, { stop }) =>
|
||||
nextPosition = matchRange.start
|
||||
@setBufferPosition matchRange.start
|
||||
stop()
|
||||
|
||||
@setBufferPosition(nextPosition or [0, 0])
|
||||
moveToEndOfWord: ->
|
||||
bufferPosition = @getBufferPosition()
|
||||
range = [bufferPosition, @editor.getEofPosition()]
|
||||
|
||||
@editor.traverseRegexMatchesInRange @wordRegex, range, (match, matchRange, { stop }) =>
|
||||
@setBufferPosition matchRange.end
|
||||
stop()
|
||||
|
||||
moveToEndOfLine: ->
|
||||
{ row } = @getBufferPosition()
|
||||
|
||||
@@ -110,6 +110,8 @@ class Editor extends View
|
||||
@on 'move-to-beginning-of-line', => @moveCursorToBeginningOfLine()
|
||||
@on 'move-to-end-of-line', => @moveCursorToEndOfLine()
|
||||
@on 'move-to-first-character-of-line', => @moveCursorToFirstCharacterOfLine()
|
||||
@on 'move-to-beginning-of-word', => @moveCursorToBeginningOfWord()
|
||||
@on 'move-to-end-of-word', => @moveCursorToEndOfWord()
|
||||
@on 'select-to-top', => @selectToTop()
|
||||
@on 'select-to-bottom', => @selectToBottom()
|
||||
@on 'select-to-end-of-line', => @selectToEndOfLine()
|
||||
@@ -369,7 +371,8 @@ class Editor extends View
|
||||
moveCursorRight: -> @compositeCursor.moveRight()
|
||||
moveCursorLeft: -> @compositeCursor.moveLeft()
|
||||
moveCursorToNextWord: -> @compositeCursor.moveToNextWord()
|
||||
moveCursorToPreviousWord: -> @compositeCursor.moveToPreviousWord()
|
||||
moveCursorToBeginningOfWord: -> @compositeCursor.moveToBeginningOfWord()
|
||||
moveCursorToEndOfWord: -> @compositeCursor.moveToEndOfWord()
|
||||
moveCursorToTop: -> @compositeCursor.moveToTop()
|
||||
moveCursorToBottom: -> @compositeCursor.moveToBottom()
|
||||
moveCursorToBeginningOfLine: -> @compositeCursor.moveToBeginningOfLine()
|
||||
|
||||
@@ -4,4 +4,6 @@ window.keymap.bindKeys '.editor'
|
||||
'meta-down': 'move-to-bottom'
|
||||
'meta-shift-down': 'select-to-bottom'
|
||||
'meta-right': 'move-to-end-of-line'
|
||||
'meta-left': 'move-to-beginning-of-line'
|
||||
'meta-left': 'move-to-beginning-of-line'
|
||||
'alt-left': 'move-to-beginning-of-word'
|
||||
'alt-right': 'move-to-end-of-word'
|
||||
@@ -3,8 +3,8 @@ window.keymap.bindKeys '.editor',
|
||||
'ctrl-b': 'move-left'
|
||||
'ctrl-p': 'move-up'
|
||||
'ctrl-n': 'move-down'
|
||||
'alt-f': 'move-to-next-word'
|
||||
'alt-b': 'move-to-previous-word'
|
||||
'alt-f': 'move-to-end-of-word'
|
||||
'alt-b': 'move-to-beginning-of-word'
|
||||
'ctrl-a': 'move-to-first-character-of-line'
|
||||
'ctrl-e': 'move-to-end-of-line'
|
||||
'ctrl-h': 'backspace'
|
||||
|
||||
Reference in New Issue
Block a user