Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix-81729 Preserve case in Search and Replace isn't working when I use group substitution #81858

Merged
merged 2 commits into from
Oct 26, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Added tests for group substitution issue
  • Loading branch information
skprabhanjan committed Oct 25, 2019
commit bb8de72061daf56f30fe7f91a19c9c73e6bf9aa5
2 changes: 1 addition & 1 deletion src/vs/workbench/services/search/common/replace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class ReplacePattern {
if (match[0] === text) {
return text.replace(this._regExp, this.buildReplaceString(match, preserveCase));
skprabhanjan marked this conversation as resolved.
Show resolved Hide resolved
}
let replaceString = text.replace(this._regExp, this.pattern);
let replaceString = text.replace(this._regExp, this.buildReplaceString(match, preserveCase));
return replaceString.substr(match.index, match[0].length - (text.length - replaceString.length));
}
return this.buildReplaceString(match, preserveCase);
Expand Down
18 changes: 17 additions & 1 deletion src/vs/workbench/services/search/test/common/replace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,5 +214,21 @@ suite('Replace Pattern test', () => {
testObject = new ReplacePattern('$0ah', { pattern: 'b(la)(?=\\stext$)', isRegExp: true });
actual = testObject.getReplaceString('this is a bla text');
assert.equal('blaah', actual);

testObject = new ReplacePattern('newrege$1', true, /Testrege(\w*)/);
actual = testObject.getReplaceString('Testregex', true);
assert.equal('Newregex', actual);

testObject = new ReplacePattern('newrege$1', true, /TESTREGE(\w*)/);
actual = testObject.getReplaceString('TESTREGEX', true);
assert.equal('NEWREGEX', actual);

testObject = new ReplacePattern('new_rege$1', true, /Test_Rege(\w*)/);
actual = testObject.getReplaceString('Test_Regex', true);
assert.equal('New_Regex', actual);

testObject = new ReplacePattern('new-rege$1', true, /Test-Rege(\w*)/);
actual = testObject.getReplaceString('Test-Regex', true);
assert.equal('New-Regex', actual);
});
});
});