mirror of
https://github.com/atom/atom.git
synced 2026-02-09 14:15:24 -05:00
Match $ in command regexes as end of line. Don't infinitely loop on substituting zero-width matches
This commit is contained in:
@@ -3,6 +3,8 @@ Command = require 'command-interpreter/command'
|
||||
module.exports =
|
||||
class Address extends Command
|
||||
execute: (editor) ->
|
||||
editor.getSelection().setBufferRange(@getRange(editor))
|
||||
range = @getRange(editor)
|
||||
editor.clearSelections()
|
||||
editor.setSelectionBufferRange(range)
|
||||
|
||||
isAddress: -> true
|
||||
|
||||
@@ -3,3 +3,6 @@ _ = require 'underscore'
|
||||
module.exports =
|
||||
class Command
|
||||
isAddress: -> false
|
||||
|
||||
regexForPattern: (pattern) ->
|
||||
new RegExp(pattern, 'm')
|
||||
|
||||
@@ -6,7 +6,7 @@ class RegexAddress extends Address
|
||||
regex: null
|
||||
|
||||
constructor: (pattern) ->
|
||||
@regex = new RegExp(pattern)
|
||||
@regex = @regexForPattern(pattern)
|
||||
|
||||
getRange: (editor) ->
|
||||
selectedRange = editor.getSelection().getBufferRange()
|
||||
|
||||
@@ -6,7 +6,7 @@ class SelectAllMatches extends Command
|
||||
@regex: null
|
||||
|
||||
constructor: (pattern) ->
|
||||
@regex = new RegExp(pattern)
|
||||
@regex = @regexForPattern(pattern)
|
||||
|
||||
execute: (editor) ->
|
||||
rangesToSelect = []
|
||||
|
||||
@@ -5,7 +5,7 @@ class Substitution extends Command
|
||||
global: false
|
||||
|
||||
constructor: (@findText, @replaceText, @options) ->
|
||||
@findRegex = new RegExp(@findText)
|
||||
@findRegex = @regexForPattern(@findText)
|
||||
@global = 'g' in @options
|
||||
|
||||
execute: (editor) ->
|
||||
@@ -27,7 +27,10 @@ class Substitution extends Command
|
||||
buffer.change([startPosition, endPosition], @replaceText)
|
||||
|
||||
if @global
|
||||
text = text[(match.index + match[0].length)..]
|
||||
startIndex = matchStartIndex + @replaceText.length
|
||||
offset = if match[0].length then 0 else 1
|
||||
startNextStringFragmentAt = match.index + match[0].length + offset
|
||||
return if startNextStringFragmentAt >= text.length
|
||||
text = text[startNextStringFragmentAt..]
|
||||
startIndex = matchStartIndex + offset + @replaceText.length
|
||||
@replace(editor, text, startIndex)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user