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

Commit 7b15d7d

Browse files
authored
Merge pull request #316 from atom/whole-word-replace-bug
Unable to replace text with special character when the search regex contains a word boundary
2 parents 81ccb55 + 32ba069 commit 7b15d7d

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

spec/text-buffer-spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const path = require('path')
2+
const TextBuffer = require('../src/text-buffer')
3+
4+
describe('when a buffer is already open', () => {
5+
it('replaces foo( with bar( using /\bfoo\\(\b/gim', () => {
6+
const filePath = path.join(__dirname, 'fixtures', 'sample.js')
7+
const buffer = new TextBuffer()
8+
buffer.setPath(filePath)
9+
buffer.setText('foo(x)')
10+
buffer.replace(/\bfoo\(\b/gim, 'bar(')
11+
12+
expect(buffer.getText()).toBe('bar(x)')
13+
})
14+
})

src/text-buffer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,8 +1608,8 @@ class TextBuffer {
16081608
let replacements = 0
16091609

16101610
this.transact(() => {
1611-
return this.scan(regex, function ({matchText, replace}) {
1612-
replace(matchText.replace(regex, replacementText))
1611+
return this.scan(regex, function ({replace}) {
1612+
replace(replacementText)
16131613
return replacements++
16141614
})
16151615
})

0 commit comments

Comments
 (0)