Skip to content

Commit 776995c

Browse files
committed
Test: Add test case for all commands
1 parent 562c2aa commit 776995c

File tree

4 files changed

+420
-41
lines changed

4 files changed

+420
-41
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ No more 6 backticks for creating code block in markdown.
107107

108108
## Link
109109

110+
- [Markdown Code Block In VSCode Markeplace](https://marketplace.visualstudio.com/items?itemName=kkangmj.vscode-markdown-extension)
110111
- [Keyboard shortcuts for VSCode](https://code.visualstudio.com/docs/getstarted/keybindings)
111112
- [Syntax highlighting for fenced code blocks](https://markdown-all-in-one.github.io/docs/guide/syntax-highlighting-for-fenced-code-blocks.html#in-editor)
112113
- [Supported languages of highlight.js](https://github.com/highlightjs/highlight.js/blob/main/SUPPORTED_LANGUAGES.md)

src/extension.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
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

Comments
 (0)