Skip to content

Commit 76c84a9

Browse files
fix 'onEmptyLineAction' Replace break indent
fix bug wrap down on last line add enum 'FormatAs' add command 'wrap.string' add command 'wrap.string.up' add command 'wrap.string.down' add new gifs for readme.md remove screenshot gifs update readme update changelog
1 parent f7c5ca6 commit 76c84a9

12 files changed

+123
-40
lines changed

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22

33
# CHANGELOG
44

5+
## 1.5.0
6+
##### 2018-01-12
7+
8+
### Added
9+
- New command `wrap.string`
10+
- New command `wrap.string.up`
11+
- New command `wrap.string.down`
12+
13+
### Fixed
14+
- Fail to log down bugs
15+
16+
It is now possible to log what you type as text. Check out the new feature in the updated README.md.
17+
18+
If you like this extensioin or have any suggestion or bug you found please hit me up on github and/or drop a rating/review on the marketplace. :)
19+
20+
Happy coding!
21+
22+
---
23+
524
## 1.4.0
625
##### 2017-11-07
726

README.md

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,51 @@
22

33
This extension wraps the word near your cursor and replaces it as an argument for `console.log`.
44

5-
If needed you can log with a __prefix__ generated from the selected variable _or_ specify your own in an input box.
6-
7-
85
## Key features
6+
7+
* Optimized for keyboard use
98
* No selection needed
109
* Wrap and replace for fast logging
11-
* Optimized for keyboard use (less mouse)
12-
* Keeps the indent when inserting lines
13-
* Can log variables both with and without prefixed text
14-
* Wrap and logs selected text if needed
10+
* Doesn't break indent
11+
* Can log variables with and without prefixed text
12+
* Supports custom prefix
1513

16-
![demo](images/screenshot.gif)
14+
> ### Type the variable to log
15+
![demo](images/screenshot_inline_replace.gif)
1716

18-
---
17+
> ### Log the variable on cursor
18+
![demo](images/screenshot_log_cursor.gif)
19+
20+
> ### Type and log it as a string
21+
![demo](images/screenshot_inline_string.gif)
22+
23+
> ### Keep your indents
24+
![demo](images/screenshot_indent.gif)
25+
26+
> ### Use custom prefix
27+
![demo](images/screenshot_custom_prefix.gif)
1928

20-
## Wrap and replace
29+
The fastest way to log your variables! Type it and press `Ctrl+Alt+W` + `W`.
2130

22-
### _Quick log on the same line_
31+
Another way to `console.log` your variables is to simply place your **mouse cursor** on them and then wrap them on the line below with `Ctrl+Alt+W` + `Down` or the line above with `Ctrl+Alt+W` + `Up`.
2332

24-
> ### Inline
33+
Does the keyboard shortcuts seem to complex? Don't worry, they feel way more comfortable than they look. :)
34+
35+
Also, you are free to rebind all keyboard shortcuts as you want in your workspace and user settings files. :)
36+
37+
38+
## Keyboard shortcuts
39+
40+
> ### Log as string
41+
*Replace the word on your cursor or the selected text*
42+
43+
* `Ctrl+Alt+W` + `W`
44+
45+
---
46+
47+
### Log on current line
48+
*Replace the variable on the mouse cursor*
49+
> ### Wrap and replace
2550
2651
* `Ctrl+Alt+W` + `W`
2752

@@ -34,18 +59,10 @@ If needed you can log with a __prefix__ generated from the selected variable _or
3459
3560
* `Ctrl+Shift+Alt+W` + `Ctrl+Shift+Alt+W`
3661

37-
38-
These commands will replace with `console.log` on the same line.
39-
40-
Use input box if you want to specify a custom prefix.
41-
4262
---
4363

44-
![demo](images/screenshot2.gif)
45-
46-
## Insert **down**
47-
48-
### _Log on the next line_
64+
### Insert **down**
65+
*Insert console.log on the line below*
4966

5067
> ### Down
5168
@@ -60,16 +77,10 @@ Use input box if you want to specify a custom prefix.
6077
6178
* `Ctrl+Shift+Alt+W` + `Ctrl+Shift+Alt+Down`
6279

63-
64-
These commands will insert `console.log` on a new line below.
65-
66-
6780
---
6881

69-
70-
## Insert **up**
71-
72-
### _Log on the line above_
82+
### Insert **up**
83+
*Insert console.log on the line below*
7384

7485
> ### Up
7586
@@ -84,5 +95,3 @@ These commands will insert `console.log` on a new line below.
8495
8596
* `Ctrl+Shift+Alt+W` + `Ctrl+Shift+Alt+Up`
8697

87-
88-
These commands will insert `console.log` on a new line above.

images/screenshot.gif

-130 KB
Binary file not shown.

images/screenshot2.gif

-130 KB
Binary file not shown.

images/screenshot_custom_prefix.gif

16.1 KB
Loading

images/screenshot_indent.gif

54.7 KB
Loading

images/screenshot_inline.gif

27.9 KB
Loading

images/screenshot_inline_replace.gif

12.1 KB
Loading

images/screenshot_inline_string.gif

13.9 KB
Loading

images/screenshot_log_cursor.gif

9.84 KB
Loading

package.json

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"type": "git",
77
"url": "https://github.com/midnightsyntax/vscode-wrap-console-log"
88
},
9-
"version": "1.4.0",
9+
"version": "1.5.0",
1010
"publisher": "midnightsyntax",
1111
"icon": "images/icon.png",
1212
"engines": {
@@ -29,7 +29,10 @@
2929
"onCommand:console.log.wrap.up.prefix.input",
3030
"onCommand:console.log.wrap.down",
3131
"onCommand:console.log.wrap.down.prefix",
32-
"onCommand:console.log.wrap.down.prefix.input"
32+
"onCommand:console.log.wrap.down.prefix.input",
33+
"onCommand:console.log.wrap.string",
34+
"onCommand:console.log.wrap.string.up",
35+
"onCommand:console.log.wrap.string.down"
3336
],
3437
"main": "out/extension.js",
3538
"contributes": {
@@ -120,6 +123,18 @@
120123
{
121124
"command": "console.log.wrap.up.input",
122125
"title": "Wrap up input console log"
126+
},
127+
{
128+
"command": "console.log.wrap.string",
129+
"title": "Wrap console.log as string"
130+
},
131+
{
132+
"command": "console.log.wrap.string.down",
133+
"title": "Wrap down console.log as string"
134+
},
135+
{
136+
"command": "console.log.wrap.string.up",
137+
"title": "Wrap up console.log as string"
123138
}
124139
],
125140
"keybindings": [
@@ -128,6 +143,21 @@
128143
"key": "ctrl+alt+w w",
129144
"when": "editorTextFocus"
130145
},
146+
{
147+
"command": "console.log.wrap.string",
148+
"key": "alt+shift+w w",
149+
"when": "editorTextFocus"
150+
},
151+
{
152+
"command": "console.log.wrap.string.down",
153+
"key": "alt+shift+w down",
154+
"when": "editorTextFocus"
155+
},
156+
{
157+
"command": "console.log.wrap.string.up",
158+
"key": "alt+shift+w up",
159+
"when": "editorTextFocus"
160+
},
131161
{
132162
"command": "console.log.wrap.down",
133163
"key": "ctrl+alt+w down",

src/extension.ts

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ export function activate(context: vscode.ExtensionContext) {
1212
vscode.window.onDidChangeActiveTextEditor(editor => currentEditor = editor);
1313

1414
let cWrap = vscode.commands.registerTextEditorCommand('console.log.wrap', (editor, edit) => handle(Wrap.Inline));
15+
let cWrapString = vscode.commands.registerTextEditorCommand('console.log.wrap.string', (editor, edit) => handle(Wrap.Inline, false, false, FormatAs.String));
16+
let cWrapStringUp = vscode.commands.registerTextEditorCommand('console.log.wrap.string.up', (editor, edit) => handle(Wrap.Up, false, false, FormatAs.String));
17+
let cWrapStringDown = vscode.commands.registerTextEditorCommand('console.log.wrap.string.down', (editor, edit) => handle(Wrap.Down, false, false, FormatAs.String));
1518
let cWrapPrefix= vscode.commands.registerTextEditorCommand('console.log.wrap.prefix', (editor, edit) => handle(Wrap.Inline, true));
1619
let cWrapInput= vscode.commands.registerTextEditorCommand('console.log.wrap.input', (editor, edit) => handle(Wrap.Inline, true, true));
1720
let cWrapUp = vscode.commands.registerTextEditorCommand('console.log.wrap.up', (editor, edit) => handle(Wrap.Up));
@@ -22,7 +25,7 @@ export function activate(context: vscode.ExtensionContext) {
2225
let cWrapDownPrefixInput = vscode.commands.registerTextEditorCommand('console.log.wrap.down.input', (editor, edit) => handle(Wrap.Down, true, true));
2326
let cSettings = vscode.commands.registerTextEditorCommand('console.log.settings', (editor, edit) => editSettings());
2427

25-
context.subscriptions.push(cWrap, cWrapUp, cWrapDown, cWrapPrefix, cWrapDownPrefix, cWrapUpPrefix, cSettings);
28+
context.subscriptions.push(cWrap, cWrapString, cWrapUp, cWrapDown, cWrapPrefix, cWrapDownPrefix, cWrapUpPrefix, cSettings);
2629
}
2730

2831
function editSettings() {
@@ -32,7 +35,7 @@ function editSettings() {
3235
window.showQuickPick(items)
3336
}
3437

35-
function handle(target: Wrap, prefix?: boolean, input?: boolean) {
38+
function handle(target: Wrap, prefix?: boolean, input?: boolean, formatAs?: FormatAs) {
3639

3740
new Promise((resolve, reject) => {
3841
let sel = currentEditor.selection;
@@ -65,7 +68,16 @@ function handle(target: Wrap, prefix?: boolean, input?: boolean) {
6568
resolve(wrapData)
6669
}
6770
} else {
68-
wrapData.txt = "console.log(".concat(txt, ");");
71+
switch (formatAs) {
72+
case FormatAs.String:
73+
wrapData.txt = "console.log('".concat(txt, "');");
74+
break;
75+
76+
default:
77+
wrapData.txt = "console.log(".concat(txt, ");");
78+
break;
79+
}
80+
6981
resolve(wrapData);
7082
}
7183
};
@@ -111,6 +123,7 @@ function handle(target: Wrap, prefix?: boolean, input?: boolean) {
111123
l = li; stop = true;
112124
}
113125
} else {
126+
if (li == wrap.doc.lineCount) li--;
114127
stop = true;
115128
}
116129
}
@@ -155,7 +168,6 @@ function handle(target: Wrap, prefix?: boolean, input?: boolean) {
155168

156169
if (!wrap.lastLine) {
157170
nxtLine = wrap.doc.lineAt(wrap.line+1);
158-
nxtNonEmpty = (nxtLine.isEmptyOrWhitespace) ? wrap.doc.lineAt(getTargetLine(Wrap.Down)) : undefined;
159171
nxtLineInd = nxtLine.text.substring(0, nxtLine.firstNonWhitespaceCharacterIndex);
160172
} else {
161173
nxtLineInd = "";
@@ -164,12 +176,20 @@ function handle(target: Wrap, prefix?: boolean, input?: boolean) {
164176
wrap.ind = vscode.workspace.getConfiguration("wrap-console-log")["autoFormat"] == true ? "" : wrap.ind;
165177
let pos = new vscode.Position(wrap.line, wrap.doc.lineAt(wrap.line).range.end.character);
166178

167-
currentEditor.edit(function(e) {
179+
currentEditor.edit((e) => {
180+
let nxtNonEmpty;
181+
if (nxtLine) {
182+
nxtNonEmpty = (nxtLine.isEmptyOrWhitespace) ? wrap.doc.lineAt(getTargetLine(Wrap.Down)) : undefined;
183+
}
168184
if (wrap.lastLine == false && nxtLine.isEmptyOrWhitespace) {
169185
if (onEmptyAction == "Insert") {
170186
e.insert(new vscode.Position(wrap.line, wrap.doc.lineAt(wrap.line).range.end.character), "\n".concat((nxtLineInd > wrap.ind ? nxtLineInd : wrap.ind), wrap.txt));
171187
} else if (onEmptyAction == "Replace") {
172-
e.replace(new vscode.Position(nxtLine.lineNumber, 0), wrap.ind.concat(wrap.txt));
188+
if (nxtLine && (nxtNonEmpty.firstNonWhitespaceCharacterIndex > 0)) {
189+
e.replace(new vscode.Position(nxtLine.lineNumber, 0), " ".repeat(nxtNonEmpty.firstNonWhitespaceCharacterIndex).concat(wrap.txt));
190+
} else {
191+
e.replace(new vscode.Position(nxtLine.lineNumber, 0), wrap.ind.concat(wrap.txt));
192+
}
173193
}
174194
} else {
175195
e.insert(new vscode.Position(wrap.line, wrap.doc.lineAt(wrap.line).range.end.character),
@@ -213,6 +233,7 @@ function getSetting(setting: string) {
213233
return vscode.workspace.getConfiguration("wrap-console-log")[setting]
214234
}
215235

236+
216237
interface WrapData {
217238
txt: string,
218239
sel: vscode.Selection,
@@ -224,6 +245,10 @@ interface WrapData {
224245
lastLine: boolean
225246
}
226247

248+
enum FormatAs {
249+
String
250+
}
251+
227252
enum Wrap {
228253
Inline,
229254
Down,

0 commit comments

Comments
 (0)