Merge ad8d42ce5b2350d3e65c187d74339e5be0a9e95a into e40a68f409d79d8699d4d2d72c9d3dcc95b78abd

This commit is contained in:
Milad Rashidikhah 2026-04-19 14:14:22 +05:00 committed by GitHub
commit e4b262cc37
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 2 deletions

View File

@ -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()

View File

@ -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));
}
);