-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
69 lines (60 loc) Β· 1.84 KB
/
main.js
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
var vscode = require("vscode");
var beeScript = require("./source/beeMovieScript.js");
var scriptLine = beeScript.scriptLine;
var scriptPara = beeScript.scriptPara;
function activate(context) {
var commands = [
vscode.commands.registerCommand("jazz.line", insertLine),
vscode.commands.registerCommand("jazz.para", insertPara),
vscode.commands.registerCommand("jazz.multiplePara", insertMultiPara),
];
// Register all commands
commands.forEach(function (command) {
context.subscriptions.push(command);
});
}
function insertText(value, totalParas) {
var editor = vscode.window.activeTextEditor;
editor.edit((edit) =>
editor.selections.forEach((selection) => {
edit.delete(selection);
// Pick a line at random
if (value === "line") {
let randomLine =
scriptLine[Math.floor(Math.random() * scriptLine.length)];
edit.insert(selection.start, randomLine);
}
// Pick a para at random
if (value === "para") {
let randomPara =
scriptPara[Math.floor(Math.random() * scriptPara.length)];
edit.insert(selection.start, randomPara);
}
// Pick multiple random paras
if (value === "multiPara") {
for (let i = 0; i < totalParas; i++) {
let randomPara =
scriptPara[Math.floor(Math.random() * scriptPara.length)] + "\n\n";
edit.insert(selection.start, randomPara);
}
}
})
);
}
function insertLine() {
insertText("line");
}
function insertPara() {
insertText("para");
}
async function insertMultiPara() {
const countList = [];
for (let i = 2; i <= 5; i++) {
countList.push(i.toString());
}
const totalParas = await vscode.window.showQuickPick(countList, {
placeHolder: "Select number of paras to insert",
});
insertText("multiPara", totalParas);
}
exports.activate = activate;