Cut each line after |||

This commit is contained in:
Mike Phares 2020-07-12 15:32:29 -07:00
parent 91cb50b187
commit 63fe43adf0
5 changed files with 24 additions and 8 deletions

Binary file not shown.

View File

@ -22,7 +22,7 @@ None
L: L:
cd "L:\GitHub\YO-VSCode" cd "L:\GitHub\YO-VSCode\type-script-helper"
yo code yo code
@ -34,7 +34,7 @@ Modify .package
Add publisher Add publisher
cd type-script-helper cd "L:\GitHub\YO-VSCode\type-script-helper"
vsce package vsce package

View File

@ -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.2", "version": "1.2.3",
"engines": { "engines": {
"vscode": "^1.40.0" "vscode": "^1.40.0"
}, },
@ -25,7 +25,8 @@
"onCommand:helper.unwrapSql", "onCommand:helper.unwrapSql",
"onCommand:helper.wrapSqlCSharp", "onCommand:helper.wrapSqlCSharp",
"onCommand:helper.wrapSqlVB", "onCommand:helper.wrapSqlVB",
"onCommand:helper.sortLength" "onCommand:helper.sortLength",
"onCommand:helper.cutEachLine"
], ],
"contributes": { "contributes": {
"commands": [ "commands": [
@ -41,7 +42,8 @@
{ "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" } { "command": "helper.sortLength", "title": "Sort by Length" },
{ "command": "helper.cutEachLine", "title": "Cut each line after |||" }
], ],
"keybindings": [ "keybindings": [
{ {

View File

@ -37,7 +37,8 @@ export function activate(context: vscode.ExtensionContext) {
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) vscode.commands.registerCommand('helper.sortLength', helper.sortLength),
vscode.commands.registerCommand('helper.cutEachLine', helper.cutEachLine)
]; ];
commands.forEach(command => context.subscriptions.push(command)); commands.forEach(command => context.subscriptions.push(command));

View File

@ -17,7 +17,8 @@ enum LinesAction {
unwrapSql, unwrapSql,
wrapSqlCSharp, wrapSqlCSharp,
wrapSqlVB, wrapSqlVB,
sortLength sortLength,
cutEachLine
} }
function removeBlanks(lines: string[]): void { function removeBlanks(lines: string[]): void {
@ -223,6 +224,16 @@ function sortLengthLogic(lines: string[]): void {
removeBlanks(lines); removeBlanks(lines);
} }
function cutEachLineLogic(lines: string[]): void {
for (let i = 0; i < lines.length; ++i) {
if(lines[i].length > 0 && lines[i].indexOf("|||") > 0) {
lines[i] = lines[i].substr(0, lines[i].indexOf("|||"));
}
lines[i] = lines[i].trim();
}
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);
@ -257,6 +268,7 @@ function linesFunction(linesAction: LinesAction): Thenable<boolean> | undefined
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; } case LinesAction.sortLength: { sortLengthLogic(lines); break; }
case LinesAction.cutEachLine: { cutEachLineLogic(lines); break; }
default: { throw new Error(); } default: { throw new Error(); }
} }
return returnLines(textEditor, startLine, endLine, lines); return returnLines(textEditor, startLine, endLine, lines);
@ -275,3 +287,4 @@ 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); export const sortLength = () => linesFunction(LinesAction.sortLength);
export const cutEachLine = () => linesFunction(LinesAction.cutEachLine);