diff --git a/spec/text-buffer-spec.js b/spec/text-buffer-spec.js new file mode 100644 index 0000000000..113a3bc2a1 --- /dev/null +++ b/spec/text-buffer-spec.js @@ -0,0 +1,14 @@ +const path = require('path') +const TextBuffer = require('../src/text-buffer') + +describe('when a buffer is already open', () => { + it('replaces foo( with bar( using /\bfoo\\(\b/gim', () => { + const filePath = path.join(__dirname, 'fixtures', 'sample.js') + const buffer = new TextBuffer() + buffer.setPath(filePath) + buffer.setText('foo(x)') + buffer.replace(/\bfoo\(\b/gim, 'bar(') + + expect(buffer.getText()).toBe('bar(x)') + }) +}) diff --git a/src/text-buffer.js b/src/text-buffer.js index df1f4775fb..73c7ffbd8b 100644 --- a/src/text-buffer.js +++ b/src/text-buffer.js @@ -1608,8 +1608,8 @@ class TextBuffer { let replacements = 0 this.transact(() => { - return this.scan(regex, function ({matchText, replace}) { - replace(matchText.replace(regex, replacementText)) + return this.scan(regex, function ({replace}) { + replace(replacementText) return replacements++ }) })