-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patheditor.js
104 lines (85 loc) · 3.51 KB
/
editor.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
export { Editor };
/*************************************************************************************************/
/* Editor */
/*************************************************************************************************/
class Editor {
constructor() {
this.emojiButton = document.getElementById("emoji-button");
this.emojiPicker = document.getElementById("emoji-picker");
this.colorButton = document.getElementById("color-button");
this.increaseFontSizeButton = document.getElementById("increase-font-size-button");
this.decreaseFontSizeButton = document.getElementById("decrease-font-size-button");
this.setupEmojiButton();
this.setupEmojiPicker();
this.setupColorButton();
this.setupFontSizeButtons();
this.editor = null;
}
init() {
this.editor = ace.edit("code-editor");
// this.editor.setOptions({
// });
this.editor.session.setMode("ace/mode/python");
}
/* Setup functions */
/*********************************************************************************************/
setupEmojiButton() {
// Show/hide the emoji picker.
this.emojiButton.addEventListener("click", (e) => {
this.emojiPicker.classList.toggle("visible");
// Automatically focus the emoji picker search text box.
const input = app.model.editor.emojiPicker.shadowRoot.getElementById("search");
if (input)
input.focus();
});
}
setupEmojiPicker() {
// When an emoji is selected.
this.emojiPicker.addEventListener('emoji-click', (e) => {
this.editor.insert(e.detail.unicode);
this.emojiPicker.classList.remove("visible");
this.editor.focus();
});
// Hide the picker when the focus is out.
this.emojiPicker.addEventListener('focusout', (e) => {
this.emojiPicker.classList.remove("visible");
});
// Hide the picker when pressing Escape.
this.emojiPicker.addEventListener('keydown', (e) => {
if (e.key == "Escape")
this.emojiPicker.classList.remove("visible");
});
}
setupColorButton() {
Coloris({
alpha: false,
closeButton: true,
closeLabel: 'Insert',
format: 'rgb',
themeMode: 'light',
})
this.colorButton.addEventListener('change', (e) => {
const color = e.target.value.substring(3);
this.editor.insert(color);
});
}
setupFontSizeButtons() {
this.increaseFontSizeButton.addEventListener("click", (e) => {
if (this.editor.getFontSize() >= 2)
this.editor.setFontSize(this.editor.getFontSize() + 1);
});
this.decreaseFontSizeButton.addEventListener("click", (e) => {
if (this.editor.getFontSize() >= 2)
this.editor.setFontSize(this.editor.getFontSize() - 1);
});
}
/* Public functions */
/*********************************************************************************************/
setCode(code) {
this.editor.setValue(code);
this.editor.clearSelection();
}
getCode() {
return this.editor.getValue();
}
};