-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.js
More file actions
52 lines (38 loc) · 1.22 KB
/
extension.js
File metadata and controls
52 lines (38 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const vscode = require('vscode');
function activate(context) {
console.log('HTML Table Maker is now active!');
const disposable = vscode.commands.registerCommand('html-table-maker-.makeTable', async function () {
const rowsInput = await vscode.window.showInputBox({ prompt: 'Enter number of rows' });
if (!rowsInput) return;
const colsInput = await vscode.window.showInputBox({ prompt: 'Enter number of columns' });
if (!colsInput) return;
const rows = parseInt(rowsInput);
const columns = parseInt(colsInput);
let table = "<table>\n";
for (let i = 0; i <= rows; i++) {
table += "\t<tr>\n";
if (i === 0) {
for (let k = 1; k <= columns; k++) {
table += "\t\t<th></th>\n";
}
} else {
for (let j = 1; j <= columns; j++) {
table += "\t\t<td></td>\n";
}
}
table += "\t</tr>\n";
}
table += "</table>";
const editor = vscode.window.activeTextEditor;
if (editor) {
editor.edit(editBuilder => {
editBuilder.insert(editor.selection.active, table);
});
} else {
vscode.window.showErrorMessage('No active editor found. Open an HTML file first.');
}
});
context.subscriptions.push(disposable);
}
function deactivate() {}
module.exports = { activate, deactivate };