From 1af0d743dba5be83df257fbf9808a63b4aeca4a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=98=E5=B0=8F=E5=A2=A8?= <2291200076@qq.com> Date: Mon, 29 Jul 2024 23:01:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BF=AB=E6=8D=B7=E9=94=AE=E5=BE=AA=E7=8E=AF?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E6=94=AF=E6=8C=81=E8=BF=87=E6=BB=A4=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E9=85=8D=E7=BD=AE=E7=9A=84=E7=A6=81=E7=94=A8=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=20(disableFormat)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main-code/cyclic-conversion.ts | 12 ++++++- src/type-definition/SupportCaseType.ts | 47 ++++++++++++++------------ 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/src/main-code/cyclic-conversion.ts b/src/main-code/cyclic-conversion.ts index 2f757c8..99fa4d9 100644 --- a/src/main-code/cyclic-conversion.ts +++ b/src/main-code/cyclic-conversion.ts @@ -3,6 +3,7 @@ import { EOL } from "../type-definition/EOLType"; import { cyclicConvertCaseOrder } from "../type-definition/SupportCaseType"; import { caseConversion } from "./conversion"; import { isStringArrayEqual, stringListArrayDuplicateRemoval } from './utils'; +import { getUserConfigurations } from './user-configuration'; interface UserSelection { currentEol: EOL @@ -64,16 +65,25 @@ function lazyConvert() { return; } + // 获取用户配置 + const disableFormatList = getUserConfigurations('disableFormat'); + const textList = userSelection.currentSelectionsText; // vscode.window.showInformationMessage('lazyConvert' + textList.join('\n')); const eol = userSelection.currentEol; const conversionsTarget: Array = [textList]; for (const cyclicConvertCase of cyclicConvertCaseOrder) { + // issue: #1 https://github.com/coder-xiaomo/variable-conversion-vscode-extension/issues/1 + // 跳过禁用的目标格式 + if (disableFormatList.includes(cyclicConvertCase.settingsKey)) { + continue; + } + // 每一个类型 const conversionsTargetItem: string[] = []; for (const line of textList) { // 选中区块的每一行 - const conversionResult: string = caseConversion(cyclicConvertCase, line, eol); + const conversionResult: string = caseConversion(cyclicConvertCase.type, line, eol); conversionsTargetItem.push(conversionResult); } conversionsTarget.push(conversionsTargetItem); diff --git a/src/type-definition/SupportCaseType.ts b/src/type-definition/SupportCaseType.ts index a6f0706..453e6e0 100644 --- a/src/type-definition/SupportCaseType.ts +++ b/src/type-definition/SupportCaseType.ts @@ -544,33 +544,38 @@ export const quickPickSupportCases: Array = [ }, ]; +export interface CyclicConvertCaseOrderItem { + type: SupportCase, + settingsKey: string, +} + /** * 通过快捷键循环转换的顺序 * @since 2024-04-08 */ -export const cyclicConvertCaseOrder = [ - SupportCase.CAMEL_CASE, - SupportCase.SNAKE_CASE, - SupportCase.PASCAL_CASE, - SupportCase.KEBAB_CASE, - SupportCase.SPACE_CASE, - SupportCase.DOT_CASE, +export const cyclicConvertCaseOrder: Array = [ + { type: SupportCase.CAMEL_CASE, settingsKey: 'camel_case' }, + { type: SupportCase.SNAKE_CASE, settingsKey: 'snake_case' }, + { type: SupportCase.PASCAL_CASE, settingsKey: 'pascal_case' }, + { type: SupportCase.KEBAB_CASE, settingsKey: 'kebab_case' }, + { type: SupportCase.SPACE_CASE, settingsKey: 'space_case' }, + { type: SupportCase.DOT_CASE, settingsKey: 'dot_case' }, - SupportCase.SNAKE_UPPER_CASE, - SupportCase.KEBAB_UPPER_CASE, - SupportCase.SPACE_UPPER_CASE, - SupportCase.DOT_UPPER_CASE, + { type: SupportCase.SNAKE_UPPER_CASE, settingsKey: 'snake_upper_case' }, + { type: SupportCase.KEBAB_UPPER_CASE, settingsKey: 'kebab_upper_case' }, + { type: SupportCase.SPACE_UPPER_CASE, settingsKey: 'space_upper_case' }, + { type: SupportCase.DOT_UPPER_CASE, settingsKey: 'dot_upper_case' }, - SupportCase.SNAKE_PASCAL_CASE, - SupportCase.KEBAB_PASCAL_CASE, - SupportCase.SPACE_PASCAL_CASE, - SupportCase.DOT_PASCAL_CASE, + { type: SupportCase.SNAKE_PASCAL_CASE, settingsKey: 'snake_pascal_case' }, + { type: SupportCase.KEBAB_PASCAL_CASE, settingsKey: 'kebab_pascal_case' }, + { type: SupportCase.SPACE_PASCAL_CASE, settingsKey: 'space_pascal_case' }, + { type: SupportCase.DOT_PASCAL_CASE, settingsKey: 'dot_pascal_case' }, - SupportCase.SNAKE_CAMEL_CASE, - SupportCase.KEBAB_CAMEL_CASE, - SupportCase.SPACE_CAMEL_CASE, - SupportCase.DOT_CAMEL_CASE, + { type: SupportCase.SNAKE_CAMEL_CASE, settingsKey: 'snake_camel_case' }, + { type: SupportCase.KEBAB_CAMEL_CASE, settingsKey: 'kebab_camel_case' }, + { type: SupportCase.SPACE_CAMEL_CASE, settingsKey: 'space_camel_case' }, + { type: SupportCase.DOT_CAMEL_CASE, settingsKey: 'dot_camel_case' }, - SupportCase.LOWER_CASE, - SupportCase.UPPER_CASE, + { type: SupportCase.LOWER_CASE, settingsKey: 'lower_case' }, + { type: SupportCase.UPPER_CASE, settingsKey: 'upper_case' }, ];