diff --git a/spec/app/text-buffer-spec.coffee b/spec/app/text-buffer-spec.coffee index 72233ba16..dbf75502d 100644 --- a/spec/app/text-buffer-spec.coffee +++ b/spec/app/text-buffer-spec.coffee @@ -546,7 +546,7 @@ describe 'Buffer', -> describe "when given a regex with a ignore case flag", -> it "does a case-insensitive search", -> matches = [] - buffer.scanInRange /cuRRent/i, [[0,0], [12,0]], (match, range) -> + buffer.scanInRange /cuRRent/i, [[0,0], [12,0]], ({match, range}) -> matches.push(match) expect(matches.length).toBe 1 @@ -554,7 +554,7 @@ describe 'Buffer', -> it "calls the iterator with the first match for the given regex in the given range", -> matches = [] ranges = [] - buffer.scanInRange /cu(rr)ent/, [[4,0], [6,44]], (match, range) -> + buffer.scanInRange /cu(rr)ent/, [[4,0], [6,44]], ({match, range}) -> matches.push(match) ranges.push(range) @@ -569,7 +569,7 @@ describe 'Buffer', -> it "calls the iterator with each match for the given regex in the given range", -> matches = [] ranges = [] - buffer.scanInRange /cu(rr)ent/g, [[4,0], [6,59]], (match, range) -> + buffer.scanInRange /cu(rr)ent/g, [[4,0], [6,59]], ({match, range}) -> matches.push(match) ranges.push(range) @@ -593,7 +593,7 @@ describe 'Buffer', -> it "calls the iterator with the truncated match", -> matches = [] ranges = [] - buffer.scanInRange /cu(r*)/g, [[4,0], [6,9]], (match, range) -> + buffer.scanInRange /cu(r*)/g, [[4,0], [6,9]], ({match, range}) -> matches.push(match) ranges.push(range) @@ -612,7 +612,7 @@ describe 'Buffer', -> it "calls the iterator with the truncated match", -> matches = [] ranges = [] - buffer.scanInRange /cu(r*)e/g, [[4,0], [6,9]], (match, range) -> + buffer.scanInRange /cu(r*)e/g, [[4,0], [6,9]], ({match, range}) -> matches.push(match) ranges.push(range) @@ -626,7 +626,7 @@ describe 'Buffer', -> 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 = [] - buffer.scanInRange /cu(rr)ent/g, [[4,0], [6,59]], (match, range, { replace }) -> + buffer.scanInRange /cu(rr)ent/g, [[4,0], [6,59]], ({range, replace}) -> ranges.push(range) replace("foo") @@ -638,7 +638,7 @@ describe 'Buffer', -> expect(buffer.lineForRow(6)).toBe ' foo < pivot ? left.push(foo) : right.push(current);' it "allows the match to be replaced with the empty string", -> - buffer.scanInRange /current/g, [[4,0], [6,59]], (match, range, { replace }) -> + buffer.scanInRange /current/g, [[4,0], [6,59]], ({replace}) -> replace("") expect(buffer.lineForRow(5)).toBe ' = items.shift();' @@ -647,7 +647,7 @@ describe 'Buffer', -> describe "when the iterator calls the 'stop' control function", -> it "stops the traversal", -> ranges = [] - buffer.scanInRange /cu(rr)ent/g, [[4,0], [6,59]], (match, range, { stop }) -> + buffer.scanInRange /cu(rr)ent/g, [[4,0], [6,59]], ({range, stop}) -> ranges.push(range) stop() if ranges.length == 2 @@ -658,7 +658,7 @@ describe 'Buffer', -> it "calls the iterator with the last match for the given regex in the given range", -> matches = [] ranges = [] - buffer.backwardsScanInRange /cu(rr)ent/, [[4,0], [6,44]], (match, range) -> + buffer.backwardsScanInRange /cu(rr)ent/, [[4,0], [6,44]], ({match, range}) -> matches.push(match) ranges.push(range) @@ -673,7 +673,7 @@ describe 'Buffer', -> it "calls the iterator with each match for the given regex in the given range, starting with the last match", -> matches = [] ranges = [] - buffer.backwardsScanInRange /cu(rr)ent/g, [[4,0], [6,59]], (match, range) -> + buffer.backwardsScanInRange /cu(rr)ent/g, [[4,0], [6,59]], ({match, range}) -> matches.push(match) ranges.push(range) @@ -695,7 +695,7 @@ describe 'Buffer', -> 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 = [] - buffer.backwardsScanInRange /cu(rr)ent/g, [[4,0], [6,59]], (match, range, { replace }) -> + buffer.backwardsScanInRange /cu(rr)ent/g, [[4,0], [6,59]], ({range, replace}) -> ranges.push(range) replace("foo") unless range.start.isEqual([6,6]) @@ -709,7 +709,7 @@ describe 'Buffer', -> describe "when the iterator calls the 'stop' control function", -> it "stops the traversal", -> ranges = [] - buffer.backwardsScanInRange /cu(rr)ent/g, [[4,0], [6,59]], (match, range, { stop }) -> + buffer.backwardsScanInRange /cu(rr)ent/g, [[4,0], [6,59]], ({range, stop}) -> ranges.push(range) stop() if ranges.length == 2 diff --git a/src/app/cursor.coffee b/src/app/cursor.coffee index 5708d4bf7..f12a78c65 100644 --- a/src/app/cursor.coffee +++ b/src/app/cursor.coffee @@ -133,20 +133,20 @@ class Cursor moveToFirstCharacterOfLine: -> position = @getBufferPosition() - range = @getCurrentLineBufferRange() + scanRange = @getCurrentLineBufferRange() newPosition = null - @editSession.scanInRange /^\s*/, range, (match, matchRange) => - newPosition = matchRange.end + @editSession.scanInRange /^\s*/, scanRange, ({range}) => + newPosition = range.end return unless newPosition newPosition = [position.row, 0] if newPosition.isEqual(position) @setBufferPosition(newPosition) skipLeadingWhitespace: -> position = @getBufferPosition() - range = @getCurrentLineBufferRange() + scanRange = @getCurrentLineBufferRange() endOfLeadingWhitespace = null - @editSession.scanInRange /^[ \t]*/, range, (match, matchRange) => - endOfLeadingWhitespace = matchRange.end + @editSession.scanInRange /^[ \t]*/, scanRange, ({range}) => + endOfLeadingWhitespace = range.end @setBufferPosition(endOfLeadingWhitespace) if endOfLeadingWhitespace.isGreaterThan(position) @@ -164,12 +164,12 @@ class Cursor allowPrevious = options.allowPrevious ? true currentBufferPosition = @getBufferPosition() previousNonBlankRow = @editSession.buffer.previousNonBlankRow(currentBufferPosition.row) - range = [[previousNonBlankRow, 0], currentBufferPosition] + scanRange = [[previousNonBlankRow, 0], currentBufferPosition] beginningOfWordPosition = null - @editSession.backwardsScanInRange (options.wordRegex ? @wordRegExp()), range, (match, matchRange, { stop }) => - if matchRange.end.isGreaterThanOrEqual(currentBufferPosition) or allowPrevious - beginningOfWordPosition = matchRange.start + @editSession.backwardsScanInRange (options.wordRegex ? @wordRegExp()), scanRange, ({range, stop}) => + if range.end.isGreaterThanOrEqual(currentBufferPosition) or allowPrevious + beginningOfWordPosition = range.start if not beginningOfWordPosition?.isEqual(currentBufferPosition) stop() @@ -178,12 +178,12 @@ class Cursor getEndOfCurrentWordBufferPosition: (options = {}) -> allowNext = options.allowNext ? true currentBufferPosition = @getBufferPosition() - range = [currentBufferPosition, @editSession.getEofBufferPosition()] + scanRange = [currentBufferPosition, @editSession.getEofBufferPosition()] endOfWordPosition = null - @editSession.scanInRange (options.wordRegex ? @wordRegExp()), range, (match, matchRange, { stop }) => - if matchRange.start.isLessThanOrEqual(currentBufferPosition) or allowNext - endOfWordPosition = matchRange.end + @editSession.scanInRange (options.wordRegex ? @wordRegExp()), scanRange, ({range, stop}) => + if range.start.isLessThanOrEqual(currentBufferPosition) or allowNext + endOfWordPosition = range.end if not endOfWordPosition?.isEqual(currentBufferPosition) stop() diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index c1bb8022d..64f6a2a6c 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -245,7 +245,7 @@ class EditSession normalizeTabsInBufferRange: (bufferRange) -> return unless @softTabs - @scanInRange /\t/, bufferRange, (match, range, {replace}) => replace(@getTabText()) + @scanInRange /\t/, bufferRange, ({replace}) => replace(@getTabText()) cutToEndOfLine: -> maintainPasteboard = false diff --git a/src/app/text-buffer.coffee b/src/app/text-buffer.coffee index 36f93724c..803e009bf 100644 --- a/src/app/text-buffer.coffee +++ b/src/app/text-buffer.coffee @@ -404,7 +404,7 @@ class Buffer range = new Range(startPosition, endPosition) keepLooping = true replacementText = null - iterator(match, range, { stop, replace }) + iterator({match, range, stop, replace }) if replacementText? @change(range, replacementText) diff --git a/src/packages/autocomplete/lib/autocomplete-view.coffee b/src/packages/autocomplete/lib/autocomplete-view.coffee index 2123c442f..8da239fc2 100644 --- a/src/packages/autocomplete/lib/autocomplete-view.coffee +++ b/src/packages/autocomplete/lib/autocomplete-view.coffee @@ -142,7 +142,7 @@ class AutocompleteView extends SelectList lineRange = [[selectionRange.start.row, 0], [selectionRange.end.row, @editor.lineLengthForBufferRow(selectionRange.end.row)]] [prefix, suffix] = ["", ""] - @currentBuffer.scanInRange @wordRegex, lineRange, (match, range, {stop}) -> + @currentBuffer.scanInRange @wordRegex, lineRange, ({match, range, stop}) -> stop() if range.start.isGreaterThan(selectionRange.end) if range.intersectsWith(selectionRange) diff --git a/src/packages/bracket-matcher/lib/bracket-matcher.coffee b/src/packages/bracket-matcher/lib/bracket-matcher.coffee index e5cc0c16c..4d80300fa 100644 --- a/src/packages/bracket-matcher/lib/bracket-matcher.coffee +++ b/src/packages/bracket-matcher/lib/bracket-matcher.coffee @@ -102,7 +102,7 @@ module.exports = regex = new RegExp("[#{_.escapeRegExp(startPair + endPair)}]", 'g') endPairPosition = null unpairedCount = 0 - buffer.scanInRange regex, scanRange, (match, range, {stop}) => + buffer.scanInRange regex, scanRange, ({match, range, stop}) => if match[0] is startPair unpairedCount++ else if match[0] is endPair @@ -116,7 +116,7 @@ module.exports = regex = new RegExp("[#{_.escapeRegExp(startPair + endPair)}]", 'g') startPairPosition = null unpairedCount = 0 - buffer.backwardsScanInRange regex, scanRange, (match, range, {stop}) => + buffer.backwardsScanInRange regex, scanRange, ({match, range, stop}) => if match[0] is endPair unpairedCount++ else if match[0] is startPair diff --git a/src/packages/command-panel/lib/commands/regex-address.coffee b/src/packages/command-panel/lib/commands/regex-address.coffee index d2828a6be..9764d0cae 100644 --- a/src/packages/command-panel/lib/commands/regex-address.coffee +++ b/src/packages/command-panel/lib/commands/regex-address.coffee @@ -24,12 +24,12 @@ class RegexAddress extends Address rangeToReturn = null scanMethodName = if @isReversed then "backwardsScanInRange" else "scanInRange" - buffer[scanMethodName] @regex, rangeToSearch, (match, range) -> + buffer[scanMethodName] @regex, rangeToSearch, ({range}) -> rangeToReturn = range if not rangeToReturn rangeToSearch = if @isReversed then rangeAfter else rangeBefore - buffer[scanMethodName] @regex, rangeToSearch, (match, range) -> + buffer[scanMethodName] @regex, rangeToSearch, ({range}) -> rangeToReturn = range if not rangeToReturn diff --git a/src/packages/command-panel/lib/commands/select-all-matches.coffee b/src/packages/command-panel/lib/commands/select-all-matches.coffee index ad1b0bca9..dc0eaef35 100644 --- a/src/packages/command-panel/lib/commands/select-all-matches.coffee +++ b/src/packages/command-panel/lib/commands/select-all-matches.coffee @@ -12,12 +12,12 @@ class SelectAllMatches extends Command compile: (project, buffer, ranges) -> deferred = $.Deferred() operations = [] - for range in ranges - buffer.scanInRange @regex, range, (match, matchRange) -> + for scanRange in ranges + buffer.scanInRange @regex, scanRange, ({range}) -> operations.push(new Operation( project: project buffer: buffer - bufferRange: matchRange + bufferRange: range )) deferred.resolve(operations) deferred.promise() diff --git a/src/packages/command-panel/lib/commands/substitution.coffee b/src/packages/command-panel/lib/commands/substitution.coffee index 66a621bc2..71a229c32 100644 --- a/src/packages/command-panel/lib/commands/substitution.coffee +++ b/src/packages/command-panel/lib/commands/substitution.coffee @@ -15,12 +15,12 @@ class Substitution extends Command compile: (project, buffer, ranges) -> deferred = $.Deferred() operations = [] - for range in ranges - buffer.scanInRange @regex, range, (match, matchRange) => + for scanRange in ranges + buffer.scanInRange @regex, scanRange, ({range}) => operations.push(new Operation( project: project buffer: buffer - bufferRange: matchRange + bufferRange: range newText: @replacementText preserveSelection: true )) diff --git a/src/packages/whitespace/lib/whitespace.coffee b/src/packages/whitespace/lib/whitespace.coffee index 087bfabd3..f5c954ba5 100644 --- a/src/packages/whitespace/lib/whitespace.coffee +++ b/src/packages/whitespace/lib/whitespace.coffee @@ -8,7 +8,7 @@ module.exports = whitespaceBeforeSave: (buffer) -> buffer.on 'will-be-saved', -> buffer.transact -> - buffer.scan /[ \t]+$/g, (match, range, { replace }) -> replace('') + buffer.scan /[ \t]+$/g, ({replace}) -> replace('') if config.get('whitespace.ensureSingleTrailingNewline') if buffer.getLastLine() is ''