Skip to content

Commit

Permalink
refactor remove command vars, comments
Browse files Browse the repository at this point in the history
remove old unused editSettings function
add 'item' prop to WrapData
add input command to activationEvents
  • Loading branch information
midnightsyntax committed Feb 13, 2018
1 parent 2481b65 commit 80fddd6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 34 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

# CHANGELOG

## 1.6.1
##### 2018-02-13

### Fixed
- Prefix value from inbox box not being used
- Input box command not activating the extension

---

## 1.6.0
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
],
"activationEvents": [
"onCommand:console.log.wrap",
"onCommand:console.log.wrap.input",
"onCommand:console.log.wrap.prefix",
"onCommand:console.log.wrap.prefix.input",
"onCommand:console.log.wrap.up",
Expand Down
56 changes: 22 additions & 34 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,21 @@ export function activate(context: vscode.ExtensionContext) {
currentEditor = vscode.window.activeTextEditor;

vscode.window.onDidChangeActiveTextEditor(editor => currentEditor = editor);

let cWrap = vscode.commands.registerTextEditorCommand('console.log.wrap', (editor, edit) => handle(Wrap.Inline));
let cWrapString = vscode.commands.registerTextEditorCommand('console.log.wrap.string', (editor, edit) => handle(Wrap.Inline, false, false, FormatAs.String));
let cWrapStringUp = vscode.commands.registerTextEditorCommand('console.log.wrap.string.up', (editor, edit) => handle(Wrap.Up, false, false, FormatAs.String));
let cWrapStringDown = vscode.commands.registerTextEditorCommand('console.log.wrap.string.down', (editor, edit) => handle(Wrap.Down, false, false, FormatAs.String));
let cWrapPrefix= vscode.commands.registerTextEditorCommand('console.log.wrap.prefix', (editor, edit) => handle(Wrap.Inline, true));
let cWrapInput= vscode.commands.registerTextEditorCommand('console.log.wrap.input', (editor, edit) => handle(Wrap.Inline, true, true));
let cWrapUp = vscode.commands.registerTextEditorCommand('console.log.wrap.up', (editor, edit) => handle(Wrap.Up));
let cWrapUpPrefix = vscode.commands.registerTextEditorCommand('console.log.wrap.up.prefix', (editor, edit) => handle(Wrap.Up, true));
let cWrapUpPrefixInput = vscode.commands.registerTextEditorCommand('console.log.wrap.up.input', (editor, edit) => handle(Wrap.Up, true, true));
let cWrapDown = vscode.commands.registerTextEditorCommand('console.log.wrap.down', (editor, edit) => handle(Wrap.Down));
let cWrapDownPrefix = vscode.commands.registerTextEditorCommand('console.log.wrap.down.prefix', (editor, edit) => handle(Wrap.Down, true));
let cWrapDownPrefixInput = vscode.commands.registerTextEditorCommand('console.log.wrap.down.input', (editor, edit) => handle(Wrap.Down, true, true));
let cSettings = vscode.commands.registerTextEditorCommand('console.log.settings', (editor, edit) => editSettings());

context.subscriptions.push(cWrap, cWrapString, cWrapUp, cWrapDown, cWrapPrefix, cWrapDownPrefix, cWrapUpPrefix, cSettings);
}

function editSettings() {
let items:QuickPickItem[] = []
let u = new vscode.Uri();
let t = workspace.openTextDocument(u)
window.showQuickPick(items)
context.subscriptions.push(
vscode.commands.registerTextEditorCommand('console.log.wrap', (editor, edit) => handle(Wrap.Inline)),
vscode.commands.registerTextEditorCommand('console.log.wrap.string', (editor, edit) => handle(Wrap.Inline, false, false, FormatAs.String)),
vscode.commands.registerTextEditorCommand('console.log.wrap.string.up', (editor, edit) => handle(Wrap.Up, false, false, FormatAs.String)),
vscode.commands.registerTextEditorCommand('console.log.wrap.string.down', (editor, edit) => handle(Wrap.Down, false, false, FormatAs.String)),
vscode.commands.registerTextEditorCommand('console.log.wrap.prefix', (editor, edit) => handle(Wrap.Inline, true)),
vscode.commands.registerTextEditorCommand('console.log.wrap.input', (editor, edit) => handle(Wrap.Inline, true, true)),
vscode.commands.registerTextEditorCommand('console.log.wrap.up', (editor, edit) => handle(Wrap.Up)),
vscode.commands.registerTextEditorCommand('console.log.wrap.up.prefix', (editor, edit) => handle(Wrap.Up, true)),
vscode.commands.registerTextEditorCommand('console.log.wrap.up.input', (editor, edit) => handle(Wrap.Up, true, true)),
vscode.commands.registerTextEditorCommand('console.log.wrap.down', (editor, edit) => handle(Wrap.Down)),
vscode.commands.registerTextEditorCommand('console.log.wrap.down.prefix', (editor, edit) => handle(Wrap.Down, true)),
vscode.commands.registerTextEditorCommand('console.log.wrap.down.input', (editor, edit) => handle(Wrap.Down, true, true))
);
}

function handle(target: Wrap, prefix?: boolean, input?: boolean, formatAs?: FormatAs) {
Expand All @@ -51,34 +43,30 @@ function handle(target: Wrap, prefix?: boolean, input?: boolean, formatAs?: Form

let doc = currentEditor.document;
let lineNumber = ran.start.line;
let txt = doc.getText(ran);
let item = doc.getText(ran);
let idx = doc.lineAt(lineNumber).firstNonWhitespaceCharacterIndex;
let ind = doc.lineAt(lineNumber).text.substring(0, idx);
let wrapData = { txt: getSetting('wrapText'), doc: doc, ran: ran, idx: idx, ind: ind, line: lineNumber, sel: sel, lastLine: doc.lineCount-1 == lineNumber } ;
let wrapData = { txt: getSetting('wrapText'), item: item, doc: doc, ran: ran, idx: idx, ind: ind, line: lineNumber, sel: sel, lastLine: doc.lineCount-1 == lineNumber } ;
if (prefix || getSetting("alwaysUsePrefix")) {
if (getSetting("alwaysInputBoxOnPrefix") == true || input) {
vscode.window.showInputBox({placeHolder: 'Prefix', value: txt, prompt: 'Use text from input box as prefix'}).then((val) => {
vscode.window.showInputBox({placeHolder: 'Prefix string', value: '', prompt: 'Use text from input box as prefix'}).then((val) => {
if (val != undefined) {
//wrapData.txt = "console.log('".concat(val.trim(), "', ", txt ,");");
wrapData.txt = wrapData.txt.replace('$txt', val);
wrapData.txt = "console.log('".concat(val.trim(), "', ", wrapData.item ,");");
resolve(wrapData)
}
})
} else {
// wrapData.txt = "console.log('".concat(txt, "', ", txt ,");");
wrapData.txt = wrapData.txt.replace('$txt', txt);
wrapData.txt = wrapData.txt.replace('$txt', item);
resolve(wrapData)
}
} else {
switch (formatAs) {
case FormatAs.String:
// wrapData.txt = "console.log('".concat(txt, "');");
wrapData.txt = wrapData.txt.replace('$txt', "'".concat(txt, "'"));
wrapData.txt = wrapData.txt.replace('$txt', "'".concat(item, "'"));
break;

default:
// wrapData.txt = "console.log(".concat(txt, ");");
wrapData.txt = wrapData.txt.replace('$txt', txt);
wrapData.txt = wrapData.txt.replace('$txt', item);
break;
}

Expand Down Expand Up @@ -237,9 +225,9 @@ function getSetting(setting: string) {
return vscode.workspace.getConfiguration("wrap-console-log")[setting]
}


interface WrapData {
txt: string,
item: string,
sel: vscode.Selection,
doc: vscode.TextDocument,
ran: vscode.Range,
Expand Down

0 comments on commit 80fddd6

Please sign in to comment.