mirror of
https://github.com/Microsoft/vscode
synced 2024-10-30 21:06:57 +00:00
Added hyphen pattern case preserve logic
This commit is contained in:
parent
78d48a09cd
commit
aa7c5a44cc
1 changed files with 22 additions and 1 deletions
|
@ -12,7 +12,11 @@ export function buildReplaceStringWithCasePreserved(matches: string[] | null, pa
|
|||
} else if (matches[0].toLowerCase() === matches[0]) {
|
||||
return pattern.toLowerCase();
|
||||
} else if (strings.containsUppercaseCharacter(matches[0][0])) {
|
||||
return pattern[0].toUpperCase() + pattern.substr(1);
|
||||
if (validateHyphenPattern(matches, pattern)) {
|
||||
return buildReplaceStringForHyphenPatterns(matches, pattern);
|
||||
} else {
|
||||
return pattern[0].toUpperCase() + pattern.substr(1);
|
||||
}
|
||||
} else {
|
||||
// we don't understand its pattern yet.
|
||||
return pattern;
|
||||
|
@ -21,3 +25,20 @@ export function buildReplaceStringWithCasePreserved(matches: string[] | null, pa
|
|||
return pattern;
|
||||
}
|
||||
}
|
||||
|
||||
function validateHyphenPattern(matches: string[], pattern: string): boolean {
|
||||
const doesConatinHyphen = matches[0].indexOf('-') !== -1 && pattern.indexOf('-') !== -1;
|
||||
const doesConatinSameNumberOfHyphens = matches[0].split('-').length === pattern.split('-').length;
|
||||
return doesConatinHyphen && doesConatinSameNumberOfHyphens;
|
||||
}
|
||||
|
||||
function buildReplaceStringForHyphenPatterns(matches: string[], pattern: string): string {
|
||||
const splitPatternAtHyphen = pattern.split('-');
|
||||
const splitMatchAtHyphen = matches[0].split('-');
|
||||
let replaceString: string = '';
|
||||
|
||||
splitPatternAtHyphen.forEach((splitValues, index) => {
|
||||
replaceString += buildReplaceStringWithCasePreserved([splitMatchAtHyphen[index]], splitValues) + '-';
|
||||
});
|
||||
return replaceString.slice(0, -1);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue