From 91cb50b18729d9d9acaaf36bfadaa508f127f288 Mon Sep 17 00:00:00 2001 From: Mike Phares Date: Sat, 11 Jul 2020 20:53:22 -0700 Subject: [PATCH] Sort by Length --- type-script-helper-1.2.2.vsix | Bin 0 -> 6261 bytes type-script-helper/package.json | 8 +++++--- type-script-helper/src/extension.ts | 3 ++- type-script-helper/src/helper.ts | 29 ++++++++++++++++++++-------- 4 files changed, 28 insertions(+), 12 deletions(-) create mode 100644 type-script-helper-1.2.2.vsix diff --git a/type-script-helper-1.2.2.vsix b/type-script-helper-1.2.2.vsix new file mode 100644 index 0000000000000000000000000000000000000000..4328233f8a735b4c571113010a2d8646def58b9d GIT binary patch literal 6261 zcmZ{I1yogCyY&I28xI|V(%m5q(n$BAyAMc*bV`RvcZ+m4l85d*(nv{5*Tw%I`uV>1 ze$O6z?6qUey`HhwT+ftL-D}^-SWv9ae02oLB03HAUFmrb{vv;xr z+cUd5S-IO8*;|>LIXSnfgTRZdK%b+E%2Ng1ak4`Cd}9$hoZ6YM;}`6Zp3t7&s#i-! zW*t5>_^@quq%#-sJ<(%s?M~OxfkUD4@k|5^wR>KAkI+}y#v{S9H~MR{88ORd?s(8D z_imhI4ysv0Qtd+~&j$~yK-$5Jw&|w302Sh*ShjtOm)whcb!R3S${3*7*NEZ`7dfg~ zIc;b54Qw5&GyrE_t+-+$8i7}o$$=*6d>YISd|TP+4*cvU^mMEt?TDpkRHp;L`zAe% zFw-}Ouj!y+ZRCXaDg){VUjxrl_7OMd8BO$s4(W()2y&M6o>Dm8(o5B4rWS@)a?qs7#hE;k`00#=1G7rT=SZHR655IgxTxzr;p$cAOUI!NJ=uD z-jWZ^`o5T!@0b6O)p^Nu^|J2!x#TJmzhsZ$eTowCzEm^o3B{*^NX9){Y-T2nkM8VM z{sLz6HkTnjEeDKw@x(3&e!0^mrF&FtwLcX$xL_{A z+zpVCch>g3xgpcV+l>+(HSyz1`lXe(yp<_(j)O<=@@F@vr$=A>2>Pk6>HA$ zH0>5cbtu};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P^vSd8 zo_dDbcP?td<_0bRMFpI8o9}$BHBEHPk!NByWsE%T4f=Ocl&^-T5`I22G)mMI%M*-s z47N)3N!(l$I+v#^-GQfnP7h)d>nP=5Cql2g{E}v_ZTZUW?oIttht z#z$Az)a?{@8A@J2vJwHLJV7JQIqNMN z6R6Ii4x=Z@i=s!Z6o|VC4+4v3gRjrpWoWVw9I9pPT?dzUrdNFnE9c?I3P-vhxE zQ^osFUw+~I5zK#s{3?Tgv*}kE{2lfFGgyCv{9P1(WBfPX{l=*EFMb-n|8(RJ3zg*H T5q^Dy_;f5i5jN=m{rP_YeDG*c literal 0 HcmV?d00001 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