mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-20 00:04:14 +08:00
Merge ad8d42ce5b2350d3e65c187d74339e5be0a9e95a into e40a68f409d79d8699d4d2d72c9d3dcc95b78abd
This commit is contained in:
commit
e4b262cc37
@ -1242,6 +1242,7 @@ export class SnakeCaseAction extends AbstractCaseAction {
|
||||
|
||||
public static caseBoundary = new BackwardsCompatibleRegExp('(\\p{Ll})(\\p{Lu})', 'gmu');
|
||||
public static singleLetters = new BackwardsCompatibleRegExp('(\\p{Lu}|\\p{N})(\\p{Lu})(\\p{Ll})', 'gmu');
|
||||
public static hyphenBoundary = new BackwardsCompatibleRegExp('(\\S)(-)(\\S)', 'gm');
|
||||
|
||||
constructor() {
|
||||
super({
|
||||
@ -1255,11 +1256,13 @@ export class SnakeCaseAction extends AbstractCaseAction {
|
||||
protected _modifyText(text: string, wordSeparators: string): string {
|
||||
const caseBoundary = SnakeCaseAction.caseBoundary.get();
|
||||
const singleLetters = SnakeCaseAction.singleLetters.get();
|
||||
if (!caseBoundary || !singleLetters) {
|
||||
const hyphenBoundary = SnakeCaseAction.hyphenBoundary.get();
|
||||
if (!caseBoundary || !singleLetters || !hyphenBoundary) {
|
||||
// cannot support this
|
||||
return text;
|
||||
}
|
||||
return (text
|
||||
.replace(hyphenBoundary, '$1_$3')
|
||||
.replace(caseBoundary, '$1_$2')
|
||||
.replace(singleLetters, '$1_$2$3')
|
||||
.toLocaleLowerCase()
|
||||
|
||||
@ -921,7 +921,8 @@ suite('Editor Contrib - Line Operations', () => {
|
||||
helloWorld();`.replace(/^\s+/gm, ''),
|
||||
`'JavaScript'`,
|
||||
'parseHTML4String',
|
||||
'_accessor: ServicesAccessor'
|
||||
'_accessor: ServicesAccessor',
|
||||
'hello-this-is-kebab-case'
|
||||
], {}, (editor) => {
|
||||
const model = editor.getModel()!;
|
||||
const uppercaseAction = new UpperCaseAction();
|
||||
@ -1046,6 +1047,11 @@ suite('Editor Contrib - Line Operations', () => {
|
||||
executeAction(snakecaseAction, editor);
|
||||
assert.strictEqual(model.getLineContent(20), '_accessor: services_accessor');
|
||||
assertSelection(editor, new Selection(20, 1, 20, 29));
|
||||
|
||||
editor.setSelection(new Selection(21, 1, 21, 25));
|
||||
executeAction(snakecaseAction, editor);
|
||||
assert.strictEqual(model.getLineContent(21), 'hello_this_is_kebab_case');
|
||||
assertSelection(editor, new Selection(21, 1, 21, 25));
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user