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

Unable to replace text with special character when the search regex contains a word boundary #316

Merged
merged 3 commits into from
Nov 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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