diff --git a/CHANGELOG.md b/CHANGELOG.md index f1d5339..57ffbd8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,7 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- Supports scrolling conversion via shortcut keys `Ctrl + Alt + [` and `Ctrl + Alt + ]` (simultaneously supports multi-line selection conversion) 支持通过快捷键滚动转换 (同时支持多行选区转换) +- Supports scrolling conversion via shortcut keys `Ctrl + Alt + [` and `Ctrl + Alt + ]` (simultaneously supports multi-line selection conversion) 支持通过快捷键循环转换 (同时支持多行选区转换) ## 1.0.7 @@ -44,7 +44,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- Add a status bar button to trigger string conversion (添加底栏按钮,支持通过底栏按钮触发字符串转换) +- Add a status bar button to trigger string conversion (添加状态栏按钮,支持通过状态栏按钮触发变量转换) ## 1.0.5 diff --git a/README.md b/README.md index aab6008..a13c57c 100644 --- a/README.md +++ b/README.md @@ -1,40 +1,67 @@ # 命名方式转换插件 Variable Conversion -一个强大的变量名转换插件,支持常用命名方式间一键转换,支持右键菜单、快捷键、底栏等多种方式使用。
-A powerful variable naming conversion extension. You can use it through the editer menu, shortcut keys and bottom bar. +一个强大的变量名转换插件,支持一键转换、循环转换,支持右键菜单、快捷键、状态栏等多种方式使用。
+A powerful variable naming conversion extension. Supports one-key conversion & cyclic conversion. You can use it through the editer menu, shortcut keys and bottom bar. + +- [x] 支持多选区 Support multi-selection +- [x] 支持多窗口 (不支持子窗口状态栏) Support subwindow (subwindow status bar are not supported) +- [x] 支持撤回 & 重做 Support undo & redo (Ctrl + Z / Ctrl + Y) ## 如何使用? How to Use? > 🔭 Tips for Chinese users: 如果您无法看到下文图片,请[点击这里查看](https://gitee.com/coder-xiaomo/variable-conversion-vscode-extension/blob/main/README.md) -#### 1. 选中代码中需要转换的内容
Select The Text To Convert +### 循环转换(Beta) Cyclic conversion(Beta) + +选中代码中需要转换的内容,然后按下 `Ctrl + Alt + [` and `Ctrl + Alt + ]` 即可前后灵活切换变量命名方式。 + +![](image/cyclic-conversion.gif) + +### 基础转换 + +**1. 选中代码中需要转换的内容** **Select The Text To Convert** ![Step1. Select The Text To Convert](image/step1-select-the-text-to-convert.gif) -> Tips:
-> 可以通过 `Ctrl + D` 快捷键选中光标所在的单词
-> You can press `Ctrl + D` to select the word near the cursor +> 小提示:
+> 1. 可以先按住 `Alt` 键不放,再鼠标先后选中多个选区
+> 2. 可以先按住 `Shift + Alt` 键不放,再按下鼠标左键,使用鼠标滑过需要选中的区块
+> 3. 可以通过 `Ctrl + D` 快捷键选中光标所在的单词
+> Tips:
+> 1. You can first hold down `Alt`, and then use the mouse to select multiple selection
+> 2. You can first hold down `Shift + Alt`, then press the left mouse button, and use the mouse to slide over the block that needs to be selected
+> 3. You can press `Ctrl + D` to select the word near the cursor
-#### 2. 按 `Shift + Alt + T`
Press `Shift + Alt + T` +**2. 按 `Shift + Alt + T`** **Press `Shift + Alt + T`** ![Step2. Press Shift + Alt + T](image/step2-press-shift-alt-t.gif) -或者点击状态栏的 `字符串转换` 按钮
+或者点击状态栏的 `变量转换` 按钮
Or click the `String Conversion` button in the status bar ![Step2. Press Status Bar Button](image/step2-press-status-bar-button.png) -或者右键 -> `字符串转换`
+或者右键 -> `变量转换`
Or right-click -> `String Conversion` ![Step2. Variable conversion on the context menu](image/step2-variable-conversion-on-context-menu.png) -或者右键 -> 将字符串转换为...
+或者右键 -> 将变量转换为...
Or right-click on the selected text -> Convert string to... ![Step2. Right-click on the selected text](image/step2-right-click-on-the-selected-text.gif) -#### 3. 选择转换目标,转换完成
Select the conversion target and complete +**3. 选择转换目标,转换完成** **Select the conversion target and complete** + +## 快捷键 + +| 功能 Feature | 快捷键 shortcut key | +| ------------------------------------------------ | ------------------- | +| 变量转换 快速选择 QuickPick | | +| 循环转换→上一个 Cyclic conversion → Previous one | Ctrl + Alt + [ | +| 循环转换→下一个 Cyclic conversion → Next one | Ctrl + Alt + ] | + + ## 支持的类型 Support Case @@ -57,8 +84,6 @@ Or right-click on the selected text -> Convert string to... | 全小写 | Lower Case | foo_bar / foobar | | 全大写 | Upper Case | FOO_BAR / FOOBAR | - - ## 反馈 Feedback 如果您觉得本插件还不够好用,有更好的使用建议;或者发现了 BUG,欢迎[前往 GitHub 仓库提 issue](https://github.com/coder-xiaomo/variable-conversion-vscode-extension/issues). 使用简体中文、繁體中文或 English 均可,不建议使用翻译软件翻译,否则可能会让文字描述变得抽象难懂。
diff --git a/image/cyclic-conversion.gif b/image/cyclic-conversion.gif new file mode 100644 index 0000000..a1aea07 Binary files /dev/null and b/image/cyclic-conversion.gif differ diff --git a/package-comment.jsonc b/package-comment.jsonc index 1a744cf..0287374 100644 --- a/package-comment.jsonc +++ b/package-comment.jsonc @@ -2,7 +2,7 @@ // 插件 id 及名称 "name": "variable-conversion", "displayName": "Variable Conversion", - "description": "一个强大的变量名转换插件,支持右键菜单、快捷键、底栏等多种方式使用,支持小驼峰、大驼峰(帕斯卡)、下划线(蛇形)、中划线(连字符/脊柱式)、空格分隔、全小写、全大写等常用命名方式(及组合)转换。 \nA powerful variable naming conversion extension. You can use it through the editer menu, shortcut keys and bottom bar. Support camel, pascal, snake, kebab(spinal), space, lower, upper case, and more.", + "description": "一个强大的变量名转换插件,支持右键菜单、快捷键、状态栏等多种方式使用,支持小驼峰、大驼峰(帕斯卡)、下划线(蛇形)、中划线(连字符/脊柱式)、空格分隔、全小写、全大写等常用命名方式(及组合)转换。 \nA powerful variable naming conversion extension. You can use it through the editer menu, shortcut keys and bottom bar. Support camel, pascal, snake, kebab(spinal), space, lower, upper case, and more.", // 版本号 "version": "1.0.8", // logo @@ -45,7 +45,7 @@ "key": "shift+alt+t", "when": "editorTextFocus" }, - // 滚动转换 上一个 + // 循环转换 上一个 { "command": "variable-conversion.cyclicConvertCase.previous", "key": "ctrl+alt+[", @@ -54,7 +54,7 @@ }, "when": "editorTextFocus" }, - // 滚动转换 下一个 + // 循环转换 下一个 { "command": "variable-conversion.cyclicConvertCase.next", "key": "ctrl+alt+]", @@ -66,22 +66,22 @@ ], "commands": [ /** - * 滚动转换 可以不添加 + * 循环转换 可以不添加 */ // { // "command": "variable-conversion.cyclicConvertCase.previous", - // "title": "字符串转换(上一个)" + // "title": "变量转换(上一个)" // }, // { // "command": "variable-conversion.cyclicConvertCase.next", - // "title": "字符串转换(下一个)" + // "title": "变量转换(下一个)" // }, /** * 右键菜单 */ { "command": "variable-conversion.convertCase", - "title": "字符串转换" + "title": "变量转换" }, /** * 右键菜单 - 子菜单 @@ -312,7 +312,7 @@ "submenus": [ { "id": "variable-conversion.stringConversionMenu", - "label": "将字符串转换为..." + "label": "将变量转换为..." } ] }, diff --git a/package.json b/package.json index 9097db5..a348c10 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "variable-conversion", "displayName": "Variable Conversion", - "description": "一个强大的变量名转换插件,支持右键菜单、快捷键、底栏等多种方式使用,支持小驼峰、大驼峰(帕斯卡)、下划线(蛇形)、中划线(连字符/脊柱式)、空格分隔、全小写、全大写等常用命名方式(及组合)转换。 \nA powerful variable naming conversion extension. You can use it through the editer menu, shortcut keys and bottom bar. Support camel, pascal, snake, kebab(spinal), space, lower, upper case, and more.", + "description": "一个强大的变量名转换插件,支持右键菜单、快捷键、状态栏等多种方式使用,支持小驼峰、大驼峰(帕斯卡)、下划线(蛇形)、中划线(连字符/脊柱式)、空格分隔、全小写、全大写等常用命名方式(及组合)转换。 \nA powerful variable naming conversion extension. You can use it through the editer menu, shortcut keys and bottom bar. Support camel, pascal, snake, kebab(spinal), space, lower, upper case, and more.", "version": "1.0.8", "icon": "image/logo.png", "publisher": "coder-xiaomo", @@ -57,7 +57,7 @@ "commands": [ { "command": "variable-conversion.convertCase", - "title": "字符串转换" + "title": "变量转换" }, { "command": "variable-conversion.toCamelCase", @@ -207,7 +207,7 @@ "submenus": [ { "id": "variable-conversion.stringConversionMenu", - "label": "将字符串转换为..." + "label": "将变量转换为..." } ] }, diff --git a/src/extension-handler/status-bar-handler.ts b/src/extension-handler/status-bar-handler.ts index 2e02cec..cca2e05 100644 --- a/src/extension-handler/status-bar-handler.ts +++ b/src/extension-handler/status-bar-handler.ts @@ -11,7 +11,7 @@ let statusBar: vscode.StatusBarItem; */ export function createStatusBarItem() { statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left); - statusBar.text = '$(find-replace)字符串转换'; + statusBar.text = '$(find-replace)变量转换'; statusBar.command = 'variable-conversion.convertCase'; // statusBar.color = 'red'; // statusBar.show(); diff --git a/src/extension.ts b/src/extension.ts index dca5648..b19aab8 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -45,7 +45,7 @@ export function activate(context: vscode.ExtensionContext) { // 判断是否展示状态栏按钮 updateStatusBarItemVisable(selectTextLength); - // 滚动转换:记录当前选中内容,并且进行转换 + // 循环转换:记录当前选中内容,并且进行转换 let eol: EOL = textEditor.document.eol === vscode.EndOfLine.CRLF ? '\r\n' : '\n'; CyclicConversion.onUserSelectionUpdated(selections, textList, eol); }; @@ -66,7 +66,7 @@ export function activate(context: vscode.ExtensionContext) { * 编辑器中光标选中位置改变触发 */ vscode.window.onDidChangeTextEditorSelection(event => { - console.log('光标选中位置改变 onDidChangeTextEditorSelection', event); + // console.log('光标选中位置改变 onDidChangeTextEditorSelection', event); // 执行 Callback onTextEditorSelectionChangeCallback(event.textEditor, event.selections); }); @@ -86,11 +86,11 @@ export function activate(context: vscode.ExtensionContext) { context.subscriptions.push(disposable); } - // 注册字符串转换 command 状态栏/快捷键/右键[字符串转换]菜单均有用到 + // 注册变量转换 command 状态栏/快捷键/右键[变量转换]菜单均有用到 let convertCaseDisposable = vscode.commands.registerCommand('variable-conversion.convertCase', handleQuickPick); context.subscriptions.push(convertCaseDisposable); - // 注册滚动转换 command + // 注册循环转换 command let disposableLoopConversionPrev = vscode.commands.registerCommand('variable-conversion.cyclicConvertCase.previous', ({ arrowKey }) => { console.log('variable-conversion.convertCase', arrowKey); CyclicConversion.previousOne(); diff --git a/src/main-code/cyclic-conversion.ts b/src/main-code/cyclic-conversion.ts index 8f052e1..acd7fb8 100644 --- a/src/main-code/cyclic-conversion.ts +++ b/src/main-code/cyclic-conversion.ts @@ -11,7 +11,7 @@ interface UserSelection { currentIndex: number isConverted: boolean conversionsTarget: Array - lastConvertedSelectionsText: string[] // 按快捷键后转换的值(如果下次触发 onUserSelectionUpdated 后传入值是这个,那么跳过,避免丢失当前滚动转换记录) + lastConvertedSelectionsText: string[] // 按快捷键后转换的值(如果下次触发 onUserSelectionUpdated 后传入值是这个,那么跳过,避免丢失当前循环转换记录) } const userSelection: UserSelection = { @@ -25,17 +25,17 @@ const userSelection: UserSelection = { }; export function onUserSelectionUpdated(selections: readonly vscode.Selection[], textList: string[], eol: EOL): void { + userSelection.currentSelections = selections; if (textList.length !== 0 && isStringArrayEqual(textList, userSelection.lastConvertedSelectionsText)) { console.log('skip onUserSelectionUpdated'); return; } console.log('onUserSelectionUpdated', textList, userSelection.lastConvertedSelectionsText); userSelection.currentEol = eol; - userSelection.currentSelections = selections; userSelection.currentSelectionsText = textList; userSelection.currentIndex = 0; userSelection.isConverted = false; - userSelection.conversionsTarget = []; + userSelection.conversionsTarget = [textList]; userSelection.lastConvertedSelectionsText = textList; } @@ -65,8 +65,9 @@ function lazyConvert() { } const textList = userSelection.currentSelectionsText; + // vscode.window.showInformationMessage('lazyConvert' + textList.join('\n')); const eol = userSelection.currentEol; - const conversionsTarget: Array = []; + const conversionsTarget: Array = [textList]; for (const cyclicConvertCase of cyclicConvertCaseOrder) { // 每一个类型 const conversionsTargetItem: string[] = []; @@ -80,9 +81,9 @@ function lazyConvert() { // 按数组去重 const noDuplicate = stringListArrayDuplicateRemoval(conversionsTarget); - console.log('noDuplicate', noDuplicate); + // console.log('noDuplicate', noDuplicate); - userSelection.conversionsTarget = conversionsTarget; + userSelection.conversionsTarget = noDuplicate; userSelection.isConverted = true; } diff --git a/src/type-definition/SupportCaseType.ts b/src/type-definition/SupportCaseType.ts index 6f81b71..5ba6414 100644 --- a/src/type-definition/SupportCaseType.ts +++ b/src/type-definition/SupportCaseType.ts @@ -232,7 +232,7 @@ const keyword = { }; /** - * 接管的字符串转换命令 + * 接管的变量转换命令 */ export const commands: Array<{ command: string; targetCase: SupportCase }> = [ { command: 'variable-conversion.toCamelCase', targetCase: SupportCase.CAMEL_CASE }, @@ -361,7 +361,7 @@ export const quickPickSupportCases = [ ]; /** - * 通过快捷键滚动转换的顺序 + * 通过快捷键循环转换的顺序 * @since 2024-04-08 */ export const cyclicConvertCaseOrder = [