Skip to content
Open
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
5 changes: 5 additions & 0 deletions src/vs/base/common/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import * as strings from './strings.js';

export function buildReplaceStringWithCasePreserved(matches: string[] | null, pattern: string): string {
if (matches && (matches[0] !== '')) {
// A caseless match has no case to preserve, so use the pattern as-is.
if (matches[0].toLowerCase() === matches[0].toUpperCase()) {
return pattern;
}

const containsHyphens = validateSpecificSpecialCharacter(matches, pattern, '-');
const containsUnderscores = validateSpecificSpecialCharacter(matches, pattern, '_');
if (containsHyphens && !containsUnderscores) {
Expand Down
10 changes: 10 additions & 0 deletions src/vs/editor/contrib/find/test/browser/replacePattern.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ suite('Replace Pattern test', () => {
assertReplace(['Foo_Bar-abc'], 'newfoo_newbar-abc', 'Newfoo_newbar-abc');
assertReplace(['foo_Bar'], 'newfoo_newbar', 'newfoo_Newbar');
assertReplace(['Foo_BAR'], 'newfoo_newbar', 'Newfoo_NEWBAR');
// #192168 - matches without any cased characters have no case to preserve
assertReplace(['()'], 'fontSize: 20', 'fontSize: 20');
assertReplace(['123'], 'Def', 'Def');
assertReplace(['!'], 'someValue', 'someValue');
assertReplace(['ABC-123'], 'Def-someValue', 'DEF-someValue');
});

test('preserve case', () => {
Expand Down Expand Up @@ -250,5 +255,10 @@ suite('Replace Pattern test', () => {
assertReplace(['Foo_Bar-abc'], 'newfoo_newbar-abc', 'Newfoo_newbar-abc');
assertReplace(['foo_Bar'], 'newfoo_newbar', 'newfoo_Newbar');
assertReplace(['foo_BAR'], 'newfoo_newbar', 'newfoo_NEWBAR');
// #192168 - matches without any cased characters have no case to preserve
assertReplace(['()'], 'fontSize: 20', 'fontSize: 20');
assertReplace(['123'], 'Def', 'Def');
assertReplace(['!'], 'someValue', 'someValue');
assertReplace(['ABC-123'], 'Def-someValue', 'DEF-someValue');
});
});