-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
98 lines (81 loc) · 2.8 KB
/
Copy pathmain.js
File metadata and controls
98 lines (81 loc) · 2.8 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
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
import plugin from './plugin.json';
import getCompletionsList from './snippets/snippets.js';
class RNAutocomplete {
constructor() {
this.id = plugin.id;
this.completer = null;
this.allowedModes = /javascript|typescript|tsx|jsx/i;
this.completionsData = [];
this.isActive = false;
}
async init() {
this.isActive = true;
// 1. Snippet verilerini hazırla
this.completionsData = getCompletionsList().map(item => ({
caption: item.caption,
value: item.snippet || item.caption,
meta: item.meta || "RN",
score: item.score || 1000, // Score'u yüksek tut ki üstte çıksın
snippet: item.snippet
}));
// 2. Completer nesnesini tanımla
this.completer = {
id: this.id,
getCompletions: (editor, session, pos, prefix, callback) => {
if (!this.isActive || prefix.length === 0) return callback(null, []);
const mode = session.getMode().$id;
if (!mode || !this.allowedModes.test(mode)) return callback(null, []);
const matches = this.completionsData.filter(item =>
item.caption.toLowerCase().includes(prefix.toLowerCase())
);
callback(null, matches);
}
};
// 3. Editör değişimlerini dinle (Önemli!)
// Acode'da editör açıldığında veya değiştiğinde completer'ı tekrar ekleyelim
this.applyCompleterToEditor();
window.toast("React Native Snippets Active!", 2000);
}
applyCompleterToEditor() {
const langTools = ace.require("ace/ext/language_tools");
if (!langTools) return;
// Hem global listeye ekle
langTools.addCompleter(this.completer);
// Hem de mevcut tüm aktif editörlere manuel ekle
const editor = editorManager.editor;
if (editor) {
editor.setOptions({
enableBasicAutocompletion: true,
enableSnippets: true,
enableLiveAutocompletion: true
});
// Eğer completer listesinde yoksa ekle
if (!editor.completers) editor.completers = [];
if (!editor.completers.find(c => c.id === this.id)) {
editor.completers.push(this.completer);
}
}
}
async destroy() {
this.isActive = false;
const langTools = ace.require("ace/ext/language_tools");
if (langTools) {
langTools.removeCompleter(this.completer);
}
const editor = editorManager.editor;
if (editor && editor.completers) {
editor.completers = editor.completers.filter(c => c.id !== this.id);
}
window.toast("React Native Snippets Removed!", 2000);
}
}
if (window.acode) {
const acodePlugin = new RNAutocomplete();
acode.setPluginInit(acodePlugin.id, async (baseUrl, $page) => {
acodePlugin.baseUrl = baseUrl;
await acodePlugin.init();
});
acode.setPluginUnmount(acodePlugin.id, () => {
acodePlugin.destroy();
});
}