Skip to content

Commit

Permalink
add custom wrap text
Browse files Browse the repository at this point in the history
add extension setting 'wrapText'
change CHANGELOG, README
  • Loading branch information
midnightsyntax committed Jan 15, 2018
1 parent 6dbe1cd commit 2481b65
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@

# CHANGELOG

---

## 1.6.0
##### 2018-01-15

### Added
- Custom wrap text!
- New config settings `.wrapText`

Specify the text to wrap with with the new setting `.wrapText`.
The default value of this setting is `console.log($txt);` where `$txt` specifies where the variable/text should be inserted. If the value of `.wrapText` does not include `$txt` vscode will warn you. Make sure you specify `$txt` ONE time if you change this setting.

---


## 1.5.0
##### 2018-01-12

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ Also, you are free to rebind all keyboard shortcuts as you want in your workspac

* `Alt+Shift+W` + `W`

##### OBS: If the string to log contains spaces you need to select the whole string

---

### Log on current line
Expand Down
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "git",
"url": "https://github.com/midnightsyntax/vscode-wrap-console-log"
},
"version": "1.5.3",
"version": "1.6.0",
"publisher": "midnightsyntax",
"icon": "images/icon.png",
"engines": {
Expand Down Expand Up @@ -84,6 +84,13 @@
"title": "Always log with the wrapped word as prefix.",
"description": "If true ALL wraps will log with the selected word as prefix.",
"default": false
},
"wrap-console-log.wrapText": {
"title": "The text to wrap with.",
"description": "Use $text to specify where in the string your variable/text should be placed.",
"type": "string",
"default": "console.log($txt);",
"pattern": "\\$txt"
}
}
},
Expand Down
14 changes: 9 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,31 @@ function handle(target: Wrap, prefix?: boolean, input?: boolean, formatAs?: Form
let txt = doc.getText(ran);
let idx = doc.lineAt(lineNumber).firstNonWhitespaceCharacterIndex;
let ind = doc.lineAt(lineNumber).text.substring(0, idx);
let wrapData = { txt: undefined, doc: doc, ran: ran, idx: idx, ind: ind, line: lineNumber, sel: sel, lastLine: doc.lineCount-1 == lineNumber } ;
let wrapData = { txt: getSetting('wrapText'), 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) => {
if (val != undefined) {
wrapData.txt = "console.log('".concat(val.trim(), "', ", txt ,");");
//wrapData.txt = "console.log('".concat(val.trim(), "', ", txt ,");");
wrapData.txt = wrapData.txt.replace('$txt', val);
resolve(wrapData)
}
})
} else {
wrapData.txt = "console.log('".concat(txt, "', ", txt ,");");
// wrapData.txt = "console.log('".concat(txt, "', ", txt ,");");
wrapData.txt = wrapData.txt.replace('$txt', txt);
resolve(wrapData)
}
} else {
switch (formatAs) {
case FormatAs.String:
wrapData.txt = "console.log('".concat(txt, "');");
// wrapData.txt = "console.log('".concat(txt, "');");
wrapData.txt = wrapData.txt.replace('$txt', "'".concat(txt, "'"));
break;

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

Expand Down

0 comments on commit 2481b65

Please sign in to comment.