-
Notifications
You must be signed in to change notification settings - Fork 53
/
dialect_select.js
76 lines (62 loc) · 2.98 KB
/
dialect_select.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
70
71
72
73
74
75
76
const vscode = acquireVsCodeApi();
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
function handle_manual_separator_change() {
document.getElementById("separator_selector").value = document.getElementById("manual_entry_option").value;
}
function handle_apply_click() {
let separator_selection_option = document.getElementById("separator_selector").value;
let manual_separator_text = document.getElementById("custom_separator_input").value;
if (!manual_separator_text) {
if (separator_selection_option == 'comma') {
manual_separator_text = ',';
} else if (separator_selection_option == 'tab') {
manual_separator_text = '\t';
} else if (separator_selection_option == 'whitespace') {
manual_separator_text = ' ';
}
}
let policy = document.getElementById("policy_selector").value;
let custom_comment_prefix = document.getElementById("custom_comment_prefix").value;
vscode.postMessage({'msg_type': 'apply_dialect', 'delim': manual_separator_text, 'policy': policy, 'comment_prefix': custom_comment_prefix});
}
async function handle_message(msg_event) {
console.log('message received at client: ' + JSON.stringify(msg_event));
var message = msg_event.data;
if (!message) {
return;
}
let message_type = message['msg_type'];
if (message_type == 'dialect_handshake') {
let selected_separator = message.selected_separator;
if (selected_separator == '\t') {
document.getElementById("separator_selector").value = document.getElementById("tab_option").value;
} else if (selected_separator == ' ') {
document.getElementById("separator_selector").value = document.getElementById("whitespace_option").value;
} else if (selected_separator) {
document.getElementById("custom_separator_input").value = selected_separator;
document.getElementById("separator_selector").value = document.getElementById("manual_entry_option").value;
}
let policy = document.getElementById("simple_option").value;
if (selected_separator == ' ') {
policy = document.getElementById("merging_option").value;
} else if (selected_separator == ',' || selected_separator == ';' || !selected_separator) {
policy = document.getElementById("rfc_option").value;
}
document.getElementById("policy_selector").value = policy;
if (message.integration_test) {
await sleep(1500);
handle_apply_click();
}
}
}
function main() {
window.addEventListener('message', handle_message);
vscode.postMessage({'msg_type': 'dialect_handshake'});
document.getElementById("custom_separator_input").addEventListener("input", handle_manual_separator_change);
document.getElementById("apply_button").addEventListener("click", handle_apply_click);
}
document.addEventListener("DOMContentLoaded", function(_event) {
main();
});