diff --git a/spec/extensions/command-interpreter-spec.coffee b/spec/extensions/command-interpreter-spec.coffee index 0fea210c7..b1ebe1ec5 100644 --- a/spec/extensions/command-interpreter-spec.coffee +++ b/spec/extensions/command-interpreter-spec.coffee @@ -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", -> diff --git a/spec/extensions/command-panel-spec.coffee b/spec/extensions/command-panel-spec.coffee index dac1a6e4e..ac2440e7a 100644 --- a/spec/extensions/command-panel-spec.coffee +++ b/spec/extensions/command-panel-spec.coffee @@ -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", -> diff --git a/src/extensions/command-panel/commands/regex-address.coffee b/src/extensions/command-panel/commands/regex-address.coffee index 37a4737ed..a236df556 100644 --- a/src/extensions/command-panel/commands/regex-address.coffee +++ b/src/extensions/command-panel/commands/regex-address.coffee @@ -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)