11"use strict" ;
22
3- import { commands , window , Selection } from "vscode" ;
4-
5- export function activate ( context : vscode . ExtensionContext ) {
3+ import {
4+ commands ,
5+ window ,
6+ Selection ,
7+ Position ,
8+ ExtensionContext ,
9+ } from "vscode" ;
10+
11+ export function activate ( context : ExtensionContext ) {
612 context . subscriptions . push (
713 commands . registerCommand (
814 "markdown.extension.codeBlock.emptyLine" ,
@@ -144,9 +150,13 @@ function xmlCodeBlock() {
144150 return codeBlock ( fenceWithEmptyLine , newPositionWithEmptyLine , "xml" ) ;
145151}
146152
147- function codeBlock ( fenceOfCodeBlock , newPositionOfCodeBlock , lang = "" ) {
153+ function codeBlock (
154+ fenceOfCodeBlock : ( lang : string , indentation : string ) => string ,
155+ newPositionOfCodeBlock : ( cursor : Position ) => Position ,
156+ lang : string = ""
157+ ) {
148158 const editor = window . activeTextEditor ;
149- if ( ! editor . selection . isEmpty ) {
159+ if ( editor === undefined || ! editor . selection . isEmpty ) {
150160 return ;
151161 }
152162 const positionOfCursor = editor . selection . active ;
@@ -164,19 +174,19 @@ function codeBlock(fenceOfCodeBlock, newPositionOfCodeBlock, lang = "") {
164174 } ) ;
165175}
166176
167- function fenceWithEmptyLine ( lang = "" , indentation ) {
177+ function fenceWithEmptyLine ( lang : string = "" , indentation : string ) {
168178 return `\`\`\`${ lang } \n${ indentation } \n${ indentation } \`\`\`` ;
169179}
170180
171- function fenceWithoutLine ( lang = "" , indentation ) {
181+ function fenceWithoutLine ( lang : string = "" , indentation : string ) {
172182 return `\`\`\`${ lang } \n${ indentation } \`\`\`` ;
173183}
174184
175- function newPositionWithEmptyLine ( newCursor ) {
185+ function newPositionWithEmptyLine ( newCursor : Position ) {
176186 return newCursor . with ( newCursor . line - 1 , newCursor . character ) ;
177187}
178188
179- function newPositionWithoutLine ( newCursor ) {
189+ function newPositionWithoutLine ( newCursor : Position ) {
180190 return newCursor . with ( newCursor . line - 1 , newCursor . character + 3 ) ;
181191}
182192
0 commit comments