forked from PKief/vscode-markdown-checkbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateCheckbox.ts
22 lines (20 loc) · 935 Bytes
/
createCheckbox.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import * as helpers from './helpers';
import * as vscode from 'vscode';
import { Position, TextEditorEdit, TextEditor } from 'vscode';
/** create a new checkbox at the current cursor position */
export const createCheckbox = (editor: TextEditor): any => {
let withBulletPoint = helpers.getConfig('withBulletPoint');
let typeOfBulletPoint = helpers.getConfig('typeOfBulletPoint');
const cursorPosition = helpers.getCursorPosition();
const line = editor.document.lineAt(helpers.getCursorPosition().line);
let hasBullet = helpers.lineHasBulletPointAlready(line);
if (helpers.lineHasCheckbox(line) === null) {
return editor.edit((editBuilder: TextEditorEdit) => {
editBuilder.insert(new Position(
line.lineNumber,
hasBullet.pos
), (withBulletPoint && !hasBullet.bullet ? typeOfBulletPoint + ' ' : '') + '[ ] ');
});
}
return null;
};