From 46f73d037f438d339c093b99356054c18df10873 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Tue, 26 Nov 2013 17:08:21 -0800 Subject: [PATCH] Fix replace on open buffers. only replace paths specified. Closes find-and-replace#85 --- spec/project-spec.coffee | 13 +++++++++++++ src/project.coffee | 1 + 2 files changed, 14 insertions(+) diff --git a/spec/project-spec.coffee b/spec/project-spec.coffee index 789b2dfc4..ff287c7e0 100644 --- a/spec/project-spec.coffee +++ b/spec/project-spec.coffee @@ -353,6 +353,19 @@ describe "Project", -> expect(editor.isModified()).toBeFalsy() + it "does not replace when the path is not specified", -> + editor = atom.project.openSync('sample.js') + editor = atom.project.openSync('sample-with-comments.js') + + results = [] + waitsForPromise -> + atom.project.replace /items/gi, 'items', [commentFilePath], (result) -> + results.push(result) + + runs -> + expect(results).toHaveLength 1 + expect(results[0].filePath).toBe commentFilePath + it "does NOT save when modified", -> editor = atom.project.openSync('sample.js') editor.buffer.change([[0,0],[0,0]], 'omg') diff --git a/src/project.coffee b/src/project.coffee index e73f68f57..c99ff2e15 100644 --- a/src/project.coffee +++ b/src/project.coffee @@ -333,6 +333,7 @@ class Project extends telepath.Model task.on 'replace:path-replaced', iterator for buffer in @buffers.getValues() + continue unless buffer.getPath() in filePaths replacements = buffer.replace(regex, replacementText, iterator) iterator({filePath: buffer.getPath(), replacements}) if replacements