Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #206 from atom/mb-space-character-class-includes-n…
Browse files Browse the repository at this point in the history
…ewlines

Treat regexps containing '\s' as multi-line
  • Loading branch information
Max Brunsfeld authored and maxbrunsfeld committed Feb 13, 2017
1 parent 47ca8f1 commit 3e26866
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions spec/text-buffer-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2179,6 +2179,7 @@ describe "TextBuffer", ->
/\w+/g # 1 word
/\w+\n\s*\w+/g, # 2 words separated by an newline (escape sequence)
RegExp("\\w+\n\\s*\w+", 'g'), # 2 words separated by a newline (literal)
/\w+\s+\w+/g, # 2 words separated by some whitespace
/\w+[^\w]+\w+/g, # 2 words separated by anything
/\w+\n\s*\w+\n\s*\w+/g, # 3 words separated by newlines (escape sequence)
RegExp("\\w+\n\\s*\\w+\n\\s*\\w+", 'g'), # 3 words separated by newlines (literal)
Expand Down Expand Up @@ -2238,6 +2239,33 @@ describe "TextBuffer", ->
buffer.scanInRange /^\s*/gm, [[10, 0], [10, 0]], ({range}) -> ranges.push(range)
expect(ranges).toEqual([[[10, 0], [10, 0]]])

it "handles multi-line patterns", ->
matchStrings = []

# The '\s' character class
buffer.scan /{\s+var/, ({matchText}) -> matchStrings.push(matchText)
expect(matchStrings).toEqual(['{\n var'])

# A literal newline character
matchStrings.length = 0
buffer.scan RegExp("{\n var"), ({matchText}) -> matchStrings.push(matchText)
expect(matchStrings).toEqual(['{\n var'])

# A '\n' escape sequence
matchStrings.length = 0
buffer.scan /{\n var/, ({matchText}) -> matchStrings.push(matchText)
expect(matchStrings).toEqual(['{\n var'])

# A negated character class in the middle of the pattern
matchStrings.length = 0
buffer.scan /{[^a] var/, ({matchText}) -> matchStrings.push(matchText)
expect(matchStrings).toEqual(['{\n var'])

# A negated character class at the beginning of the pattern
matchStrings.length = 0
buffer.scan /[^a] var/, ({matchText}) -> matchStrings.push(matchText)
expect(matchStrings).toEqual(['\n var'])

describe "::backwardsScanInRange(range, regex, fn)", ->
beforeEach ->
filePath = require.resolve('./fixtures/sample.js')
Expand Down
2 changes: 1 addition & 1 deletion src/helpers.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Point = require './point'

MULTI_LINE_REGEX_REGEX = /\\r|\\n|\r|\n|^\[\^|[^\\]\[\^/
MULTI_LINE_REGEX_REGEX = /\\s|\\r|\\n|\r|\n|^\[\^|[^\\]\[\^/

module.exports =
spliceArray: (array, start, removedCount, insertedItems=[]) ->
Expand Down

0 comments on commit 3e26866

Please sign in to comment.