mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Regex's in the command panel are treated as case-insensitive if there are no non-escaped letters in the pattern
/hello becomes /hello/i /he\Slo becomes /he\Slo/i /Hello/i becomes /Hello/i /Hello/ becomes /Hello/
This commit is contained in:
@@ -161,6 +161,22 @@ describe "CommandInterpreter", ->
|
||||
expect(editSession.lineForScreenRow(5).fold).toBeUndefined()
|
||||
expect(editSession.lineForScreenRow(10).fold).toBeDefined()
|
||||
|
||||
it "is case-insentive when the pattern contains no non-escaped uppercase letters (behavior copied from vim)", ->
|
||||
waitsForPromise ->
|
||||
editSession.setSelectedBufferRange([[4,16], [4,20]])
|
||||
interpreter.eval('/array', editSession)
|
||||
|
||||
runs ->
|
||||
expect(editSession.getSelection().getBufferRange()).toEqual [[11,14], [11,19]]
|
||||
|
||||
waitsForPromise ->
|
||||
editSession.setSelectedBufferRange([[4,16], [4,20]])
|
||||
interpreter.eval('/a\\Sray', editSession) # You must escape the backslash, otherwise it is treated as an escaped 'S'
|
||||
|
||||
runs ->
|
||||
expect(editSession.getSelection().getBufferRange()).toEqual [[11,14], [11,19]]
|
||||
|
||||
|
||||
describe "address range", ->
|
||||
describe "when two addresses are specified", ->
|
||||
it "selects from the begining of the left address to the end of the right address", ->
|
||||
|
||||
@@ -241,7 +241,7 @@ describe "CommandPanel", ->
|
||||
expect(commandInterpreter.lastRelativeAddress).toBeUndefined()
|
||||
rootView.trigger 'command-panel:set-selection-as-regex-address'
|
||||
expect(commandInterpreter.lastRelativeAddress.subcommands.length).toBe 1
|
||||
expect(commandInterpreter.lastRelativeAddress.subcommands[0].regex.toString()).toEqual "/\\(items\\)/"
|
||||
expect(commandInterpreter.lastRelativeAddress.subcommands[0].regex.toString()).toEqual "/\\(items\\)/i"
|
||||
|
||||
describe "when command-panel:find-in-file is triggered on an editor", ->
|
||||
it "pre-populates the command panel's editor with / and moves the cursor to the last column", ->
|
||||
|
||||
@@ -6,9 +6,15 @@ class RegexAddress extends Address
|
||||
regex: null
|
||||
reverse: null
|
||||
|
||||
constructor: (pattern, isReversed) ->
|
||||
constructor: (pattern, isReversed, options) ->
|
||||
flags = ""
|
||||
pattern = pattern.source if pattern.source
|
||||
|
||||
patternContainsCapitalLetter = /[^\\][A-Z]/.test(pattern)
|
||||
flags += "i" unless patternContainsCapitalLetter
|
||||
@isReversed = isReversed
|
||||
@regex = new RegExp(pattern)
|
||||
|
||||
@regex = new RegExp(pattern, flags)
|
||||
|
||||
getRange: (buffer, range) ->
|
||||
rangeBefore = new Range([0, 0], range.start)
|
||||
|
||||
Reference in New Issue
Block a user