Merge branch 'master' of github.com:github/atom

This commit is contained in:
Nathan Sobo 2012-03-29 11:12:23 -07:00
commit e56ced8f3b
7 changed files with 99 additions and 6 deletions

View File

@ -243,6 +243,41 @@ describe 'Buffer', ->
expect(matches[2][1]).toBe 'rr'
expect(ranges[2]).toEqual [[6,34], [6,41]]
describe "when the last regex match exceeds the end of the range", ->
describe "when the portion of the match within the range also matches the regex", ->
it "calls the iterator with the truncated match", ->
matches = []
ranges = []
buffer.traverseRegexMatchesInRange /cu(r*)/g, [[4,0], [6,9]], (match, range) ->
matches.push(match)
ranges.push(range)
expect(matches.length).toBe 2
expect(ranges.length).toBe 2
expect(matches[0][0]).toBe 'curr'
expect(matches[0][1]).toBe 'rr'
expect(ranges[0]).toEqual [[5,6], [5,10]]
expect(matches[1][0]).toBe 'cur'
expect(matches[1][1]).toBe 'r'
expect(ranges[1]).toEqual [[6,6], [6,9]]
describe "when the portion of the match within the range does not matches the regex", ->
it "calls the iterator with the truncated match", ->
matches = []
ranges = []
buffer.traverseRegexMatchesInRange /cu(r*)e/g, [[4,0], [6,9]], (match, range) ->
matches.push(match)
ranges.push(range)
expect(matches.length).toBe 1
expect(ranges.length).toBe 1
expect(matches[0][0]).toBe 'curre'
expect(matches[0][1]).toBe 'rr'
expect(ranges[0]).toEqual [[5,6], [5,11]]
describe "when the iterator calls the 'replace' control function with a replacement string", ->
it "replaces each occurrence of the regex match with the string", ->
ranges = []

View File

@ -875,7 +875,7 @@ describe "Editor", ->
expect(editor.getSelection().isReversed()).toBeFalsy()
describe "select-to-beginning-of-line", ->
it "selects text from cusor position to end of line", ->
it "selects text from cusor position to beginning of line", ->
editor.setCursorScreenPosition [12,2]
editor.addCursorAtScreenPosition [11,3]
editor.trigger 'select-to-beginning-of-line'
@ -908,6 +908,40 @@ describe "Editor", ->
expect(selection2.getBufferRange()).toEqual [[11,3], [11,44]]
expect(selection2.isReversed()).toBeFalsy()
describe "select-to-beginning-of-word", ->
it "selects text from cusor position to beginning of word", ->
editor.setCursorScreenPosition [0,13]
editor.addCursorAtScreenPosition [3,49]
editor.trigger 'select-to-beginning-of-word'
expect(editor.getCursors().length).toBe 2
[cursor1, cursor2] = editor.getCursors()
expect(cursor1.getBufferPosition()).toEqual [0,4]
expect(cursor2.getBufferPosition()).toEqual [3,47]
expect(editor.getSelections().length).toBe 2
[selection1, selection2] = editor.getSelections()
expect(selection1.getBufferRange()).toEqual [[0,4], [0,13]]
expect(selection1.isReversed()).toBeTruthy()
expect(selection2.getBufferRange()).toEqual [[3,47], [3,49]]
expect(selection2.isReversed()).toBeTruthy()
describe "select-to-end-of-word", ->
it "selects text from cusor position to end of word", ->
editor.setCursorScreenPosition [0,4]
editor.addCursorAtScreenPosition [3,48]
editor.trigger 'select-to-end-of-word'
expect(editor.getCursors().length).toBe 2
[cursor1, cursor2] = editor.getCursors()
expect(cursor1.getBufferPosition()).toEqual [0,13]
expect(cursor2.getBufferPosition()).toEqual [3,50]
expect(editor.getSelections().length).toBe 2
[selection1, selection2] = editor.getSelections()
expect(selection1.getBufferRange()).toEqual [[0,4], [0,13]]
expect(selection1.isReversed()).toBeFalsy()
expect(selection2.getBufferRange()).toEqual [[3,48], [3,50]]
expect(selection2.isReversed()).toBeFalsy()
describe "multiple cursors", ->
it "places multiple cursor with meta-click", ->
editor.attachToDom()

View File

@ -158,7 +158,7 @@ class Buffer
if matchEndIndex > endIndex
regex.lastIndex = 0
if matchStartIndex < endIndex and match = regex.exec(text[matchStartIndex..endIndex])
if matchStartIndex < endIndex and match = regex.exec(text[matchStartIndex...endIndex])
matchLength = match[0].length
matchEndIndex = matchStartIndex + matchLength
else

View File

@ -95,6 +95,14 @@ class CompositeSeleciton
selection.selectToEndOfLine() for selection in @getSelections()
@mergeIntersectingSelections()
selectToBeginningOfWord: ->
selection.selectToBeginningOfWord() for selection in @getSelections()
@mergeIntersectingSelections reverse: true
selectToEndOfWord: ->
selection.selectToEndOfWord() for selection in @getSelections()
@mergeIntersectingSelections()
setBufferRange: (bufferRange, options) ->
@getLastSelection().setBufferRange(bufferRange, options)

View File

@ -116,6 +116,8 @@ class Editor extends View
@on 'select-to-bottom', => @selectToBottom()
@on 'select-to-end-of-line', => @selectToEndOfLine()
@on 'select-to-beginning-of-line', => @selectToBeginningOfLine()
@on 'select-to-end-of-word', => @selectToEndOfWord()
@on 'select-to-beginning-of-word', => @selectToBeginningOfWord()
buildCursorAndSelection: ->
@compositeSelection = new CompositeSelection(this)
@ -395,8 +397,10 @@ class Editor extends View
selectDown: -> @compositeSelection.selectDown()
selectToTop: -> @compositeSelection.selectToTop()
selectToBottom: -> @compositeSelection.selectToBottom()
selectToEndOfLine: -> @compositeSelection.selectToEndOfLine()
selectToBeginningOfLine: -> @compositeSelection.selectToBeginningOfLine()
selectToEndOfLine: -> @compositeSelection.selectToEndOfLine()
selectToBeginningOfWord: -> @compositeSelection.selectToBeginningOfWord()
selectToEndOfWord: -> @compositeSelection.selectToEndOfWord()
selectToScreenPosition: (position) -> @compositeSelection.selectToScreenPosition(position)
clearSelections: -> @compositeSelection.clearSelections()

View File

@ -1,9 +1,13 @@
window.keymap.bindKeys '.editor'
'meta-up': 'move-to-top'
'meta-shift-up': 'select-to-top'
'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'
'alt-left': 'move-to-beginning-of-word'
'alt-right': 'move-to-end-of-word'
'alt-right': 'move-to-end-of-word'
'meta-shift-up': 'select-to-top'
'meta-shift-down': 'select-to-bottom'
'meta-shift-left': 'select-to-beginning-of-line'
'meta-shift-right': 'select-to-end-of-line'
'alt-shift-left': 'select-to-beginning-of-word'
'alt-shift-right': 'select-to-end-of-word'

View File

@ -236,6 +236,14 @@ class Selection extends View
@modifySelection =>
@cursor.moveToEndOfLine()
selectToBeginningOfWord: ->
@modifySelection =>
@cursor.moveToBeginningOfWord()
selectToEndOfWord: ->
@modifySelection =>
@cursor.moveToEndOfWord()
cut: (maintainPasteboard=false) ->
@copy(maintainPasteboard)
@delete()