mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-03-30 08:40:29 -04:00
Merge from vscode 6e530127a1bb8ffbd1bfb77dc680c321dc0d71f5 (#6844)
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { CharCode } from 'vs/base/common/charCode';
|
||||
import { containsUppercaseCharacter } from 'vs/base/common/strings';
|
||||
import { buildReplaceStringWithCasePreserved } from 'vs/base/common/search';
|
||||
|
||||
const enum ReplacePatternKind {
|
||||
StaticValue = 0,
|
||||
@@ -51,17 +51,8 @@ export class ReplacePattern {
|
||||
|
||||
public buildReplaceString(matches: string[] | null, preserveCase?: boolean): string {
|
||||
if (this._state.kind === ReplacePatternKind.StaticValue) {
|
||||
if (preserveCase && matches && (matches[0] !== '')) {
|
||||
if (matches[0].toUpperCase() === matches[0]) {
|
||||
return this._state.staticValue.toUpperCase();
|
||||
} else if (matches[0].toLowerCase() === matches[0]) {
|
||||
return this._state.staticValue.toLowerCase();
|
||||
} else if (containsUppercaseCharacter(matches[0][0])) {
|
||||
return this._state.staticValue[0].toUpperCase() + this._state.staticValue.substr(1);
|
||||
} else {
|
||||
// we don't understand its pattern yet.
|
||||
return this._state.staticValue;
|
||||
}
|
||||
if (preserveCase) {
|
||||
return buildReplaceStringWithCasePreserved(matches, this._state.staticValue);
|
||||
} else {
|
||||
return this._state.staticValue;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { ReplacePattern, ReplacePiece, parseReplaceString } from 'vs/editor/contrib/find/replacePattern';
|
||||
import { buildReplaceStringWithCasePreserved } from 'vs/base/common/search';
|
||||
|
||||
suite('Replace Pattern test', () => {
|
||||
|
||||
@@ -154,6 +155,29 @@ suite('Replace Pattern test', () => {
|
||||
assert.equal(actual, 'a{}');
|
||||
});
|
||||
|
||||
test('buildReplaceStringWithCasePreserved test', () => {
|
||||
let replacePattern = 'Def';
|
||||
let actual: string | string[] = 'abc';
|
||||
|
||||
assert.equal(buildReplaceStringWithCasePreserved([actual], replacePattern), 'def');
|
||||
actual = 'Abc';
|
||||
assert.equal(buildReplaceStringWithCasePreserved([actual], replacePattern), 'Def');
|
||||
actual = 'ABC';
|
||||
assert.equal(buildReplaceStringWithCasePreserved([actual], replacePattern), 'DEF');
|
||||
|
||||
actual = ['abc', 'Abc'];
|
||||
assert.equal(buildReplaceStringWithCasePreserved(actual, replacePattern), 'def');
|
||||
actual = ['Abc', 'abc'];
|
||||
assert.equal(buildReplaceStringWithCasePreserved(actual, replacePattern), 'Def');
|
||||
actual = ['ABC', 'abc'];
|
||||
assert.equal(buildReplaceStringWithCasePreserved(actual, replacePattern), 'DEF');
|
||||
|
||||
actual = ['AbC'];
|
||||
assert.equal(buildReplaceStringWithCasePreserved(actual, replacePattern), 'Def');
|
||||
actual = ['aBC'];
|
||||
assert.equal(buildReplaceStringWithCasePreserved(actual, replacePattern), 'Def');
|
||||
});
|
||||
|
||||
test('preserve case', () => {
|
||||
let replacePattern = parseReplaceString('Def');
|
||||
let actual = replacePattern.buildReplaceString(['abc'], true);
|
||||
|
||||
Reference in New Issue
Block a user