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 #316 from atom/whole-word-replace-bug
Browse files Browse the repository at this point in the history
Unable to replace text with special character when the search regex contains a word boundary
  • Loading branch information
darangi authored Nov 16, 2019
2 parents 81ccb55 + 32ba069 commit 7b15d7d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 14 additions & 0 deletions spec/text-buffer-spec.js
Original file line number Diff line number Diff line change
@@ -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)')
})
})
4 changes: 2 additions & 2 deletions src/text-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++
})
})
Expand Down

0 comments on commit 7b15d7d

Please # to comment.