Sort by Length
This commit is contained in:
parent
ff449a9c5f
commit
91cb50b187
BIN
type-script-helper-1.2.2.vsix
Normal file
BIN
type-script-helper-1.2.2.vsix
Normal file
Binary file not shown.
@ -4,7 +4,7 @@
|
|||||||
"description": "Helper for VS Code in TypeScript",
|
"description": "Helper for VS Code in TypeScript",
|
||||||
"publisher": "IFX",
|
"publisher": "IFX",
|
||||||
"repository": "https://github.com/mikepharesjr/YO-VSCode/tree/master/type-script-helper",
|
"repository": "https://github.com/mikepharesjr/YO-VSCode/tree/master/type-script-helper",
|
||||||
"version": "1.2.1",
|
"version": "1.2.2",
|
||||||
"engines": {
|
"engines": {
|
||||||
"vscode": "^1.40.0"
|
"vscode": "^1.40.0"
|
||||||
},
|
},
|
||||||
@ -24,7 +24,8 @@
|
|||||||
"onCommand:helper.sortNormal",
|
"onCommand:helper.sortNormal",
|
||||||
"onCommand:helper.unwrapSql",
|
"onCommand:helper.unwrapSql",
|
||||||
"onCommand:helper.wrapSqlCSharp",
|
"onCommand:helper.wrapSqlCSharp",
|
||||||
"onCommand:helper.wrapSqlVB"
|
"onCommand:helper.wrapSqlVB",
|
||||||
|
"onCommand:helper.sortLength"
|
||||||
],
|
],
|
||||||
"contributes": {
|
"contributes": {
|
||||||
"commands": [
|
"commands": [
|
||||||
@ -39,7 +40,8 @@
|
|||||||
{ "command": "helper.sortNormal", "title": "My Sort lines (ascending, case sensitive)" },
|
{ "command": "helper.sortNormal", "title": "My Sort lines (ascending, case sensitive)" },
|
||||||
{ "command": "helper.unwrapSql", "title": "Un-wrap Sql" },
|
{ "command": "helper.unwrapSql", "title": "Un-wrap Sql" },
|
||||||
{ "command": "helper.wrapSqlCSharp", "title": "Wrap Sql for C#" },
|
{ "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": [
|
"keybindings": [
|
||||||
{
|
{
|
||||||
|
@ -36,7 +36,8 @@ export function activate(context: vscode.ExtensionContext) {
|
|||||||
vscode.commands.registerCommand('helper.sortNormal', helper.sortNormal),
|
vscode.commands.registerCommand('helper.sortNormal', helper.sortNormal),
|
||||||
vscode.commands.registerCommand('helper.unwrapSql', helper.unwrapSql),
|
vscode.commands.registerCommand('helper.unwrapSql', helper.unwrapSql),
|
||||||
vscode.commands.registerCommand('helper.wrapSqlCSharp', helper.wrapSqlCSharp),
|
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));
|
commands.forEach(command => context.subscriptions.push(command));
|
||||||
|
@ -16,7 +16,8 @@ enum LinesAction {
|
|||||||
sortNormal,
|
sortNormal,
|
||||||
unwrapSql,
|
unwrapSql,
|
||||||
wrapSqlCSharp,
|
wrapSqlCSharp,
|
||||||
wrapSqlVB
|
wrapSqlVB,
|
||||||
|
sortLength
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeBlanks(lines: string[]): void {
|
function removeBlanks(lines: string[]): void {
|
||||||
@ -140,12 +141,6 @@ function prettySqlLogic(lines: string[]): void {
|
|||||||
removeBlanks(lines);
|
removeBlanks(lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
function makeSorter(algorithm?: SortingAlgorithm): ArrayTransformer {
|
|
||||||
return function (lines: string[]): string[] {
|
|
||||||
return lines.sort(algorithm);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function removeCommentLogic(lines: string[]): void {
|
function removeCommentLogic(lines: string[]): void {
|
||||||
for (let i = 0; i < lines.length; ++i) {
|
for (let i = 0; i < lines.length; ++i) {
|
||||||
lines[i] = lines[i].trim();
|
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 {
|
function sortNormalLogic(lines: string[]): void {
|
||||||
var transformers: ArrayTransformer[] = [];
|
var transformers: ArrayTransformer[] = [];
|
||||||
transformers.push(makeSorter());
|
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[]) {
|
function returnLines(textEditor: vscode.TextEditor, startLine: number, endLine: number, lines: string[]) {
|
||||||
return textEditor.edit(editBuilder => {
|
return textEditor.edit(editBuilder => {
|
||||||
const range = new vscode.Range(startLine, 0, endLine, textEditor.document.lineAt(endLine).text.length);
|
const range = new vscode.Range(startLine, 0, endLine, textEditor.document.lineAt(endLine).text.length);
|
||||||
@ -245,6 +256,7 @@ function linesFunction(linesAction: LinesAction): Thenable<boolean> | undefined
|
|||||||
case LinesAction.unwrapSql: { unwrapSqlLogic(lines); break; }
|
case LinesAction.unwrapSql: { unwrapSqlLogic(lines); break; }
|
||||||
case LinesAction.wrapSqlCSharp: { wrapSqlCSharpLogic(lines); break; }
|
case LinesAction.wrapSqlCSharp: { wrapSqlCSharpLogic(lines); break; }
|
||||||
case LinesAction.wrapSqlVB: { wrapSqlVBLogic(lines); break; }
|
case LinesAction.wrapSqlVB: { wrapSqlVBLogic(lines); break; }
|
||||||
|
case LinesAction.sortLength: { sortLengthLogic(lines); break; }
|
||||||
default: { throw new Error(); }
|
default: { throw new Error(); }
|
||||||
}
|
}
|
||||||
return returnLines(textEditor, startLine, endLine, lines);
|
return returnLines(textEditor, startLine, endLine, lines);
|
||||||
@ -262,3 +274,4 @@ export const sortNormal = () => linesFunction(LinesAction.sortNormal);
|
|||||||
export const unwrapSql = () => linesFunction(LinesAction.unwrapSql);
|
export const unwrapSql = () => linesFunction(LinesAction.unwrapSql);
|
||||||
export const wrapSqlCSharp = () => linesFunction(LinesAction.wrapSqlCSharp);
|
export const wrapSqlCSharp = () => linesFunction(LinesAction.wrapSqlCSharp);
|
||||||
export const wrapSqlVB = () => linesFunction(LinesAction.wrapSqlVB);
|
export const wrapSqlVB = () => linesFunction(LinesAction.wrapSqlVB);
|
||||||
|
export const sortLength = () => linesFunction(LinesAction.sortLength);
|
Loading…
x
Reference in New Issue
Block a user