-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.js
67 lines (58 loc) · 2.78 KB
/
default.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
let henko_mae;
document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('form').forEach(form => form.reset());
if (psa.filename !== undefined) {
document.getElementById('contents').setSelectionRange(0, 0);
// ファイルに変更があるときは示す
henko_mae = document.getElementById('contents').value;
document.getElementById('contents').addEventListener('keyup', () => {
document.getElementById('henko').innerText = document.getElementById('contents').value !== henko_mae ? '* ' : '';
});
// 保存ボタンのクリックで編集中のファイルを保存する
document.getElementById('save').addEventListener('click', e => {
e.preventDefault();
const xhr = new XMLHttpRequest();
xhr.open('POST', './?cwd=' + psa.cwd + '&filename=' + psa.filename);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onreadystatechange = () => {
if(xhr.readyState === 4) {
henko_mae = document.getElementById('contents').value;
document.getElementById('henko').innerText = '';
document.getElementById('contents').focus();
}
};
xhr.send('contents=' + encodeURIComponent(document.getElementById('contents').value));
});
// 行ジャンプのクリックで任意の行にジャンプする
document.getElementById('go_to_line').addEventListener('click', e => {
const gyo_bango = parseInt(prompt('Line number:'));
document.getElementById('contents').setSelectionRange(
document.getElementById('contents').value.match(new RegExp('([^\n]*\n){' + (gyo_bango - 1) + '}'))[0].length,
document.getElementById('contents').value.match(new RegExp('([^\n]*\n){' + gyo_bango + '}'))[0].length
);
document.getElementById('contents').focus();
});
document.getElementById('contents').addEventListener('keydown', e => {
if (e.code === 'Tab') {
e.preventDefault();
const start = e.target.selectionStart;
const end = e.target.selectionEnd;
if (end === start) {
// Tabキーの押下でTabの挿入を行う
e.target.value = e.target.value.substring(0, start) + '\t' + e.target.value.substring(start);
e.target.setSelectionRange(start + 1, start + 1);
} else {
// 文字列選択時はTabキーの押下でインデントを行う
// 文字列選択時はShift + Tabキーの押下でインデントの解除を行う
const sentaku = e.target.value.substring(start, end).replace(e.shiftKey ? /^\t/gm : /^/gm, e.shiftKey ? '' : '\t').replace(/^\s+$/gm, '');
e.target.value = e.target.value.substring(0, start) + sentaku + e.target.value.substring(end);
e.target.setSelectionRange(start, start + sentaku.length);
}
}
});
document.getElementById('contents').focus();
}
else {
document.querySelector('[name="command"]').focus();
}
});