循环滚动修复几处小逻辑问题;更新 README (滚动转换改为循环转换,字符串转换改为变量转换)
This commit is contained in:
@@ -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();
|
||||
|
@@ -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();
|
||||
|
@@ -11,7 +11,7 @@ interface UserSelection {
|
||||
currentIndex: number
|
||||
isConverted: boolean
|
||||
conversionsTarget: Array<string[]>
|
||||
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<string[]> = [];
|
||||
const conversionsTarget: Array<string[]> = [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;
|
||||
}
|
||||
|
||||
|
@@ -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 = [
|
||||
|
Reference in New Issue
Block a user