@@ -12,32 +12,32 @@ let commandList: vscode.Disposable[] = [];
12
12
* @returns [开始行, 结束行, 开始列, 结束列]
13
13
*/
14
14
function getTextEditorPosition ( ) : number [ ] {
15
- let st_line : number = < number > ( vscode . window . activeTextEditor ?. selection . start . line ) ;
16
- let st_character : number = < number > ( vscode . window . activeTextEditor ?. selection . start . character ) ;
17
- let ed_line : number = < number > ( vscode . window . activeTextEditor ?. selection . end . line ) ;
18
- let ed_character : number = < number > ( vscode . window . activeTextEditor ?. selection . end . character ) ;
15
+ let stLine : number = < number > ( vscode . window . activeTextEditor ?. selection . start . line ) ;
16
+ let stCharacter : number = < number > ( vscode . window . activeTextEditor ?. selection . start . character ) ;
17
+ let edLine : number = < number > ( vscode . window . activeTextEditor ?. selection . end . line ) ;
18
+ let edCharacter : number = < number > ( vscode . window . activeTextEditor ?. selection . end . character ) ;
19
19
20
- // console.log("添加文字-start", st_line, st_character );
21
- // console.log("添加文字-end", ed_line, ed_character );
20
+ // console.log("添加文字-start", stLine, stCharacter );
21
+ // console.log("添加文字-end", edLine, edCharacter );
22
22
23
- return [ st_line , ed_line , st_character , ed_character ] ;
23
+ return [ stLine , edLine , stCharacter , edCharacter ] ;
24
24
}
25
25
26
26
// add_both_fixed
27
27
commandList . push (
28
28
// 添加在选中文字的两边,光标位置不动
29
- vscode . commands . registerCommand ( "add_both_fixed" , ( label , content_l , content_r ) => {
29
+ vscode . commands . registerCommand ( "add_both_fixed" , ( label , contentL , contentR ) => {
30
30
// 快捷键匹配
31
- if ( label == "ctrl_b" ) {
32
- content_l = content_r = "**" ;
33
- } else if ( label == "ctrl_i" ) {
34
- content_l = content_r = "*" ;
31
+ if ( label === "ctrl_b" ) {
32
+ contentL = contentR = "**" ;
33
+ } else if ( label === "ctrl_i" ) {
34
+ contentL = contentR = "*" ;
35
35
}
36
36
vscode . window . activeTextEditor ?. edit ( ( editBuilder ) => {
37
- let [ st_line , ed_line , st_character , ed_character ] = getTextEditorPosition ( ) ;
37
+ let [ stLine , edLine , stCharacter , edCharacter ] = getTextEditorPosition ( ) ;
38
38
39
- editBuilder . insert ( new vscode . Position ( st_line , st_character ) , content_l ) ;
40
- editBuilder . insert ( new vscode . Position ( ed_line , ed_character ) , content_r ) ;
39
+ editBuilder . insert ( new vscode . Position ( stLine , stCharacter ) , contentL ) ;
40
+ editBuilder . insert ( new vscode . Position ( edLine , edCharacter ) , contentR ) ;
41
41
} ) ;
42
42
} )
43
43
) ;
@@ -55,9 +55,9 @@ commandList.push(
55
55
content = "### " ;
56
56
}
57
57
vscode . window . activeTextEditor ?. edit ( ( editBuilder ) => {
58
- let [ st_line , ...rest ] = getTextEditorPosition ( ) ;
58
+ let [ stLine , ...rest ] = getTextEditorPosition ( ) ;
59
59
60
- editBuilder . insert ( new vscode . Position ( st_line , 0 ) , content ) ;
60
+ editBuilder . insert ( new vscode . Position ( stLine , 0 ) , content ) ;
61
61
} ) ;
62
62
} )
63
63
) ;
@@ -67,9 +67,9 @@ commandList.push(
67
67
// 添加在当前位置,光标位置不动
68
68
vscode . commands . registerCommand ( "add_cur_fixed" , ( label , content ) => {
69
69
vscode . window . activeTextEditor ?. edit ( ( editBuilder ) => {
70
- let [ st_line , , st_character , ] = getTextEditorPosition ( ) ;
70
+ let [ stLine , , stCharacter , ] = getTextEditorPosition ( ) ;
71
71
72
- editBuilder . insert ( new vscode . Position ( st_line , st_character ) , content ) ;
72
+ editBuilder . insert ( new vscode . Position ( stLine , stCharacter ) , content ) ;
73
73
} ) ;
74
74
} )
75
75
) ;
@@ -79,9 +79,9 @@ commandList.push(
79
79
// 添加下一行开头,光标位置不动
80
80
vscode . commands . registerCommand ( "add_nxt_fixed" , ( label , content ) => {
81
81
vscode . window . activeTextEditor ?. edit ( ( editBuilder ) => {
82
- let [ st_line , ...rest ] = getTextEditorPosition ( ) ;
82
+ let [ stLine , ...rest ] = getTextEditorPosition ( ) ;
83
83
84
- editBuilder . insert ( new vscode . Position ( st_line + 1 , 0 ) , content ) ;
84
+ editBuilder . insert ( new vscode . Position ( stLine + 1 , 0 ) , content ) ;
85
85
} ) ;
86
86
} )
87
87
) ;
@@ -95,16 +95,16 @@ commandList.push(
95
95
canSelectMany : false ,
96
96
canSelectFolders : false
97
97
} ) . then ( res => {
98
- if ( res != undefined && res . length != 0 ) {
98
+ if ( res !== undefined && res . length != = 0 ) {
99
99
let uri = res [ 0 ] . path ;
100
100
uri = uri . substring ( 1 , uri . length ) ;
101
101
vscode . window . activeTextEditor ?. edit ( ( editBuilder ) => {
102
- let [ st_line , ...rest ] = getTextEditorPosition ( ) ;
102
+ let [ stLine , ...rest ] = getTextEditorPosition ( ) ;
103
103
104
- editBuilder . insert ( new vscode . Position ( st_line + 1 , 0 ) , "" ) ;
104
+ editBuilder . insert ( new vscode . Position ( stLine + 1 , 0 ) , "" ) ;
105
105
} ) ;
106
106
}
107
- } )
107
+ } ) ;
108
108
} )
109
109
) ;
110
110
@@ -126,7 +126,7 @@ function makeTable(row: number, col: number, align: number): string {
126
126
content += "\n" ;
127
127
// 插入对齐行
128
128
content += "|" ;
129
- let alignStr : string = align == 0 ? ":--:" : align == 1 ? ":---" : "---:" ;
129
+ let alignStr : string = align === 0 ? ":--:" : align = == 1 ? ":---" : "---:" ;
130
130
for ( let i = 0 ; i < col ; i ++ ) {
131
131
content += alignStr + "|" ;
132
132
}
@@ -152,31 +152,31 @@ commandList.push(
152
152
vscode . window . showInputBox ( {
153
153
placeHolder : '请输入表格的行数,默认为2'
154
154
} ) . then ( res => {
155
- if ( res == undefined ) throw "no input" ;
155
+ if ( res === undefined ) { throw new Error ( "no input" ) ; }
156
156
else {
157
- row = isNaN ( Number ( res ) ) || res == "" ? row : Number ( res ) ;
157
+ row = isNaN ( Number ( res ) ) || res === "" ? row : Number ( res ) ;
158
158
return vscode . window . showInputBox ( {
159
159
placeHolder : '请输入表格的列数,默认为2'
160
- } )
160
+ } ) ;
161
161
}
162
162
} ) . then ( res => {
163
- if ( res == undefined ) throw "no input" ;
163
+ if ( res === undefined ) { throw new Error ( "no input" ) ; }
164
164
else {
165
- col = isNaN ( Number ( res ) ) || res == "" ? col : Number ( res ) ;
165
+ col = isNaN ( Number ( res ) ) || res === "" ? col : Number ( res ) ;
166
166
return vscode . window . showInputBox ( {
167
167
placeHolder : '请输入表格对齐方式' ,
168
168
prompt : '0:居中对齐(默认),1:左对齐,2:右对齐'
169
- } )
169
+ } ) ;
170
170
}
171
171
} ) . then ( res => {
172
172
align = isNaN ( Number ( res ) ) ? align : Number ( res ) ;
173
173
// 检查行列必须大于0
174
- if ( row <= 0 || col <= 0 || align < 0 || align > 2 ) throw "input error" ;
174
+ if ( row <= 0 || col <= 0 || align < 0 || align > 2 ) { throw new Error ( "input error" ) ; }
175
175
// 插入视图
176
176
vscode . window . activeTextEditor ?. edit ( ( editBuilder ) => {
177
- let [ st_line , ...rest ] = getTextEditorPosition ( ) ;
177
+ let [ stLine , ...rest ] = getTextEditorPosition ( ) ;
178
178
179
- editBuilder . insert ( new vscode . Position ( st_line + 1 , 0 ) , makeTable ( row , col , align ) ) ;
179
+ editBuilder . insert ( new vscode . Position ( stLine + 1 , 0 ) , makeTable ( row , col , align ) ) ;
180
180
} ) ;
181
181
} ) ;
182
182
} )
@@ -193,34 +193,34 @@ commandList.push(
193
193
vscode . window . showInputBox ( {
194
194
placeHolder : '请输入label信息,如"下载量","访问量"...,默认为"label"'
195
195
} ) . then ( res => {
196
- if ( res == undefined ) throw "no input" ;
196
+ if ( res === undefined ) { throw new Error ( "no input" ) ; }
197
197
else {
198
- _label = res == "" ? _label : res ;
198
+ _label = res === "" ? _label : res ;
199
199
return vscode . window . showInputBox ( {
200
200
placeHolder : '请输入message信息,如"10k"...,默认为"message"'
201
- } )
201
+ } ) ;
202
202
}
203
203
} ) . then ( res => {
204
- if ( res == undefined ) throw "no input" ;
204
+ if ( res === undefined ) { throw new Error ( "no input" ) ; }
205
205
else {
206
- _msg = res == "" ? _msg : res ;
206
+ _msg = res === "" ? _msg : res ;
207
207
return vscode . window . showQuickPick ( [
208
208
'brightgreen' , 'yellow' , 'orange' , 'red' , 'blue' , 'success' , 'important' , 'critical' , 'informational' , 'blueviolet'
209
209
] , {
210
210
canPickMany : false ,
211
211
placeHolder : '请选择颜色'
212
- } )
212
+ } ) ;
213
213
}
214
214
} ) . then ( res => {
215
- _style = res == undefined ? _style : res ;
215
+ _style = res === undefined ? _style : res ;
216
216
// 构造内容
217
217
let content : string = "" ;
218
218
219
219
// 插入视图
220
220
vscode . window . activeTextEditor ?. edit ( ( editBuilder ) => {
221
- let [ st_line , ...rest ] = getTextEditorPosition ( ) ;
221
+ let [ stLine , ...rest ] = getTextEditorPosition ( ) ;
222
222
223
- editBuilder . insert ( new vscode . Position ( st_line + 1 , 0 ) , content ) ;
223
+ editBuilder . insert ( new vscode . Position ( stLine + 1 , 0 ) , content ) ;
224
224
} ) ;
225
225
} ) ;
226
226
} )
@@ -246,6 +246,6 @@ export function initWebViewCommand(): vscode.Disposable[] {
246
246
commandList . push ( vscode . commands . registerCommand ( "nav_web" , ( label , url ) => {
247
247
const webView = createWebView ( vscode . ViewColumn . Active , label , url ) ;
248
248
commandList . push ( webView ) ;
249
- } ) )
249
+ } ) ) ;
250
250
return commandList ;
251
251
}
0 commit comments