diff --git a/type-script-helper-1.2.2.vsix b/type-script-helper-1.2.2.vsix new file mode 100644 index 0000000..4328233 Binary files /dev/null and b/type-script-helper-1.2.2.vsix differ diff --git a/type-script-helper/package.json b/type-script-helper/package.json index 67a856a..ab9db72 100644 --- a/type-script-helper/package.json +++ b/type-script-helper/package.json @@ -4,7 +4,7 @@ "description": "Helper for VS Code in TypeScript", "publisher": "IFX", "repository": "https://github.com/mikepharesjr/YO-VSCode/tree/master/type-script-helper", - "version": "1.2.1", + "version": "1.2.2", "engines": { "vscode": "^1.40.0" }, @@ -24,7 +24,8 @@ "onCommand:helper.sortNormal", "onCommand:helper.unwrapSql", "onCommand:helper.wrapSqlCSharp", - "onCommand:helper.wrapSqlVB" + "onCommand:helper.wrapSqlVB", + "onCommand:helper.sortLength" ], "contributes": { "commands": [ @@ -39,7 +40,8 @@ { "command": "helper.sortNormal", "title": "My Sort lines (ascending, case sensitive)" }, { "command": "helper.unwrapSql", "title": "Un-wrap Sql" }, { "command": "helper.wrapSqlCSharp", "title": "Wrap Sql for C#" }, - { "command": "helper.wrapSqlVB", "title": "Wrap Sql for VB" } + { "command": "helper.wrapSqlVB", "title": "Wrap Sql for VB" }, + { "command": "helper.sortLength", "title": "Sort by Length" } ], "keybindings": [ { diff --git a/type-script-helper/src/extension.ts b/type-script-helper/src/extension.ts index 5c37e5e..854999e 100644 --- a/type-script-helper/src/extension.ts +++ b/type-script-helper/src/extension.ts @@ -36,7 +36,8 @@ export function activate(context: vscode.ExtensionContext) { vscode.commands.registerCommand('helper.sortNormal', helper.sortNormal), vscode.commands.registerCommand('helper.unwrapSql', helper.unwrapSql), vscode.commands.registerCommand('helper.wrapSqlCSharp', helper.wrapSqlCSharp), - vscode.commands.registerCommand('helper.wrapSqlVB', helper.wrapSqlVB) + vscode.commands.registerCommand('helper.wrapSqlVB', helper.wrapSqlVB), + vscode.commands.registerCommand('helper.sortLength', helper.sortLength) ]; commands.forEach(command => context.subscriptions.push(command)); diff --git a/type-script-helper/src/helper.ts b/type-script-helper/src/helper.ts index 74e1252..45e2225 100644 --- a/type-script-helper/src/helper.ts +++ b/type-script-helper/src/helper.ts @@ -16,7 +16,8 @@ enum LinesAction { sortNormal, unwrapSql, wrapSqlCSharp, - wrapSqlVB + wrapSqlVB, + sortLength } function removeBlanks(lines: string[]): void { @@ -140,12 +141,6 @@ function prettySqlLogic(lines: string[]): void { removeBlanks(lines); } -function makeSorter(algorithm?: SortingAlgorithm): ArrayTransformer { - return function (lines: string[]): string[] { - return lines.sort(algorithm); - }; -} - function removeCommentLogic(lines: string[]): void { for (let i = 0; i < lines.length; ++i) { lines[i] = lines[i].trim(); @@ -158,6 +153,12 @@ function removeCommentLogic(lines: string[]): void { } } +function makeSorter(algorithm?: SortingAlgorithm): ArrayTransformer { + return function (lines: string[]): string[] { + return lines.sort(algorithm); + }; +} + function sortNormalLogic(lines: string[]): void { var transformers: ArrayTransformer[] = []; transformers.push(makeSorter()); @@ -212,6 +213,16 @@ function wrapSqlVBLogic(lines: string[]): void { } } +function sortLengthLogic(lines: string[]): void { + lines.sort(function(a, b) { + // ASC -> a.length - b.length + // DESC -> b.length - a.length + return a.length - b.length || // sort by length, if equal then + a.localeCompare(b); // sort by dictionary order + }); + removeBlanks(lines); +} + function returnLines(textEditor: vscode.TextEditor, startLine: number, endLine: number, lines: string[]) { return textEditor.edit(editBuilder => { const range = new vscode.Range(startLine, 0, endLine, textEditor.document.lineAt(endLine).text.length); @@ -245,6 +256,7 @@ function linesFunction(linesAction: LinesAction): Thenable | undefined case LinesAction.unwrapSql: { unwrapSqlLogic(lines); break; } case LinesAction.wrapSqlCSharp: { wrapSqlCSharpLogic(lines); break; } case LinesAction.wrapSqlVB: { wrapSqlVBLogic(lines); break; } + case LinesAction.sortLength: { sortLengthLogic(lines); break; } default: { throw new Error(); } } return returnLines(textEditor, startLine, endLine, lines); @@ -261,4 +273,5 @@ export const removeComment = () => linesFunction(LinesAction.removeComment); export const sortNormal = () => linesFunction(LinesAction.sortNormal); export const unwrapSql = () => linesFunction(LinesAction.unwrapSql); export const wrapSqlCSharp = () => linesFunction(LinesAction.wrapSqlCSharp); -export const wrapSqlVB = () => linesFunction(LinesAction.wrapSqlVB); \ No newline at end of file +export const wrapSqlVB = () => linesFunction(LinesAction.wrapSqlVB); +export const sortLength = () => linesFunction(LinesAction.sortLength); \ No newline at end of file