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

Conflicts:
	src/app/cursor.coffee
This commit is contained in:
Nathan Sobo
2012-04-09 14:47:55 -06:00
7 changed files with 38 additions and 37 deletions

View File

@@ -162,12 +162,17 @@ class Buffer
@mode = new (require("ace/mode/#{modeName}").Mode)
scanRegexMatchesInRange: (regex, range, iterator) ->
scanInRange: (regex, range, iterator) ->
range = Range.fromObject(range)
global = regex.global
regex = new RegExp(regex.source, 'gm')
traverseRecursively = (text, startIndex, endIndex, lengthDelta) =>
text = @getText()
startIndex = @characterIndexForPosition(range.start)
endIndex = @characterIndexForPosition(range.end)
lengthDelta = 0
while true
regex.lastIndex = startIndex
return unless match = regex.exec(text)
@@ -186,9 +191,9 @@ class Buffer
startPosition = @positionForCharacterIndex(matchStartIndex + lengthDelta)
endPosition = @positionForCharacterIndex(matchEndIndex + lengthDelta)
range = new Range(startPosition, endPosition)
recurse = true
keepLooping = true
replacementText = null
stop = -> recurse = false
stop = -> keepLooping = false
replace = (text) -> replacementText = text
iterator(match, range, { stop, replace })
@@ -200,25 +205,21 @@ class Buffer
matchStartIndex++
matchEndIndex++
if global and recurse
traverseRecursively(text, matchEndIndex, endIndex, lengthDelta)
break unless global and keepLooping
startIndex = matchEndIndex
startIndex = @characterIndexForPosition(range.start)
endIndex = @characterIndexForPosition(range.end)
traverseRecursively(@getText(), startIndex, endIndex, 0)
backwardsTraverseRegexMatchesInRange: (regex, range, iterator) ->
backwardsScanInRange: (regex, range, iterator) ->
global = regex.global
regex = new RegExp(regex.source, 'gm')
matches = []
@scanRegexMatchesInRange regex, range, (match, matchRange) ->
@scanInRange regex, range, (match, matchRange) ->
matches.push([match, matchRange])
matches.reverse()
recurse = true
stop = -> recurse = false
keepLooping = true
stop = -> keepLooping = false
replacementText = null
replace = (text) -> replacementText = text
@@ -226,7 +227,7 @@ class Buffer
replacementText = null
iterator(match, matchRange, { stop, replace })
@change(matchRange, replacementText) if replacementText
return unless global and recurse
return unless global and keepLooping
_.extend(Buffer.prototype, EventEmitter)

View File

@@ -12,14 +12,14 @@ class RegexAddress extends Address
rangeToSearch = new Range(currentRange.end, editor.getEofPosition())
rangeToReturn = null
editor.buffer.scanRegexMatchesInRange @regex, rangeToSearch, (match, range) ->
editor.buffer.scanInRange @regex, rangeToSearch, (match, range) ->
rangeToReturn = range
if rangeToReturn
rangeToReturn
else
rangeToSearch = new Range([0, 0], rangeToSearch.start)
editor.buffer.scanRegexMatchesInRange @regex, rangeToSearch, (match, range) ->
editor.buffer.scanInRange @regex, rangeToSearch, (match, range) ->
rangeToReturn = range
rangeToReturn or currentRange

View File

@@ -10,6 +10,6 @@ class SelectAllMatches extends Command
execute: (editor, currentRange) ->
rangesToSelect = []
editor.buffer.scanRegexMatchesInRange @regex, currentRange, (match, range) ->
editor.buffer.scanInRange @regex, currentRange, (match, range) ->
rangesToSelect.push(range)
rangesToSelect

View File

@@ -10,6 +10,6 @@ class Substitution extends Command
@regex = new RegExp(pattern, options.join(''))
execute: (editor, currentRange) ->
editor.buffer.scanRegexMatchesInRange @regex, currentRange, (match, matchRange, { replace }) =>
editor.buffer.scanInRange @regex, currentRange, (match, matchRange, { replace }) =>
replace(@replacementText)
[currentRange]

View File

@@ -86,7 +86,7 @@ class Cursor extends View
range = [bufferPosition, @editor.getEofPosition()]
nextPosition = null
@editor.scanRegexMatchesInRange @wordRegex, range, (match, matchRange, { stop }) =>
@editor.scanInRange @wordRegex, range, (match, matchRange, { stop }) =>
if matchRange.start.isGreaterThan(bufferPosition)
nextPosition = matchRange.start
stop()
@@ -104,7 +104,7 @@ class Cursor extends View
currentBufferPosition = @getBufferPosition()
beginningOfWordPosition = currentBufferPosition
range = [[0,0], currentBufferPosition]
@editor.backwardsTraverseRegexMatchesInRange @wordRegex, range, (match, matchRange, { stop }) =>
@editor.backwardsScanInRange @wordRegex, range, (match, matchRange, { stop }) =>
if matchRange.end.isGreaterThanOrEqual(currentBufferPosition) or allowPrevious
beginningOfWordPosition = matchRange.start
stop()
@@ -115,7 +115,7 @@ class Cursor extends View
position = null
bufferPosition = @getBufferPosition()
range = [bufferPosition, @editor.getEofPosition()]
@editor.scanRegexMatchesInRange @wordRegex, range, (match, matchRange, { stop }) =>
@editor.scanInRange @wordRegex, range, (match, matchRange, { stop }) =>
position = matchRange.end
if not allowNext and matchRange.start.isGreaterThan(bufferPosition)
position = bufferPosition
@@ -140,7 +140,7 @@ class Cursor extends View
position = @getBufferPosition()
range = @editor.rangeForBufferRow(position.row)
newPosition = null
@editor.scanRegexMatchesInRange /^\s*/, range, (match, matchRange) =>
@editor.scanInRange /^\s*/, range, (match, matchRange) =>
newPosition = matchRange.end
newPosition = [position.row, 0] if newPosition.isEqual(position)
@setBufferPosition(newPosition)

View File

@@ -412,8 +412,8 @@ class Editor extends View
lineForBufferRow: (row) -> @buffer.lineForRow(row)
lineLengthForBufferRow: (row) -> @buffer.lineLengthForRow(row)
rangeForBufferRow: (row) -> @buffer.rangeForRow(row)
scanRegexMatchesInRange: (args...) -> @buffer.scanRegexMatchesInRange(args...)
backwardsTraverseRegexMatchesInRange: (args...) -> @buffer.backwardsTraverseRegexMatchesInRange(args...)
scanInRange: (args...) -> @buffer.scanInRange(args...)
backwardsScanInRange: (args...) -> @buffer.backwardsScanInRange(args...)
insertText: (text) ->
@compositeSelection.insertText(text)