From 2fa2feacafa95a82e363e8b036f2ad95f08d5227 Mon Sep 17 00:00:00 2001 From: Wliu <50Wliu@users.noreply.github.com> Date: Wed, 9 Aug 2017 22:52:39 -0400 Subject: [PATCH 1/3] Multiline is important, don't forget to set it --- src/workspace.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/workspace.js b/src/workspace.js index 3bf112461..ad37630eb 100644 --- a/src/workspace.js +++ b/src/workspace.js @@ -1949,7 +1949,7 @@ module.exports = class Workspace extends Model { } if (!outOfProcessFinished.length) { - let flags = 'g' + let flags = 'gm' // set multiline flag so ^ and $ match start/end of line, not file if (regex.ignoreCase) { flags += 'i' } const task = Task.once( From 95b216f2345589aa36ea6801babb27bd6526a226 Mon Sep 17 00:00:00 2001 From: Wliu <50Wliu@users.noreply.github.com> Date: Wed, 9 Aug 2017 23:15:33 -0400 Subject: [PATCH 2/3] Add multiline spec --- spec/workspace-spec.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/spec/workspace-spec.js b/spec/workspace-spec.js index bdd5677c8..add555f28 100644 --- a/spec/workspace-spec.js +++ b/spec/workspace-spec.js @@ -2394,6 +2394,22 @@ i = /test/; #FIXME\ expect(results[0].replacements).toBe(6) }) }) + + it('uses the multiline flag when searching', () => { + const filePath = path.join(projectDir, 'sample.js') + fs.copyFileSync(path.join(fixturesDir, 'sample.js'), filePath) + + const results = [] + waitsForPromise(() => + atom.workspace.replace(/;$/gi, 'items', [filePath], result => results.push(result)) + ) + + runs(() => { + expect(results).toHaveLength(1) + expect(results[0].filePath).toBe(filePath) + expect(results[0].replacements).toBe(8) + }) + }) }) describe('when a buffer is already open', () => { From 8963cf495517bddf197441f54deb112167d8b209 Mon Sep 17 00:00:00 2001 From: Wliu <50Wliu@users.noreply.github.com> Date: Thu, 10 Aug 2017 13:24:46 -0400 Subject: [PATCH 3/3] Only use multiline if the flag is passed in --- spec/workspace-spec.js | 4 ++-- src/workspace.js | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/spec/workspace-spec.js b/spec/workspace-spec.js index add555f28..476a4ba5b 100644 --- a/spec/workspace-spec.js +++ b/spec/workspace-spec.js @@ -2395,13 +2395,13 @@ i = /test/; #FIXME\ }) }) - it('uses the multiline flag when searching', () => { + it('does not discard the multiline flag', () => { const filePath = path.join(projectDir, 'sample.js') fs.copyFileSync(path.join(fixturesDir, 'sample.js'), filePath) const results = [] waitsForPromise(() => - atom.workspace.replace(/;$/gi, 'items', [filePath], result => results.push(result)) + atom.workspace.replace(/;$/gmi, 'items', [filePath], result => results.push(result)) ) runs(() => { diff --git a/src/workspace.js b/src/workspace.js index ad37630eb..17c6b2a8b 100644 --- a/src/workspace.js +++ b/src/workspace.js @@ -1949,7 +1949,8 @@ module.exports = class Workspace extends Model { } if (!outOfProcessFinished.length) { - let flags = 'gm' // set multiline flag so ^ and $ match start/end of line, not file + let flags = 'g' + if (regex.multiline) { flags += 'm' } if (regex.ignoreCase) { flags += 'i' } const task = Task.once(