Skip to content

Commit 0f73dec

Browse files
committed
Update codeit-autocomplete.js
1 parent ed4fa3c commit 0f73dec

File tree

1 file changed

+70
-45
lines changed

1 file changed

+70
-45
lines changed

lib/plugins/codeit-autocomplete.js

Lines changed: 70 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -46,41 +46,6 @@ acp.initLang = (lang) => {
4646

4747
}
4848

49-
acp.lang.css.init = () => {
50-
51-
let CSSProps = [];
52-
53-
CSSProps = Array.from(window.getComputedStyle(document.documentElement));
54-
55-
CSSProps.push('padding');
56-
CSSProps.push('margin');
57-
CSSProps.push('border');
58-
CSSProps.push('flex');
59-
CSSProps.push('grid');
60-
CSSProps.push('gap');
61-
CSSProps.push('background');
62-
CSSProps.push('overflow');
63-
CSSProps.push('transition');
64-
CSSProps.push('animation');
65-
CSSProps.push('-webkit-user-select');
66-
67-
acp.lang.css.props = CSSProps;
68-
69-
}
70-
71-
acp.lang.js.init = () => {
72-
73-
const iframe = document.createElement('iframe');
74-
75-
body.append(iframe);
76-
77-
acp.lang.js.props = iframe.contentWindow;
78-
79-
}
80-
81-
// add language alias / temp @@
82-
acp.lang.javascript = acp.lang.js;
83-
8449

8550

8651
acp.autocomplete = async (lang) => {
@@ -105,9 +70,22 @@ acp.autocomplete = async (lang) => {
10570
const textBeforeCursor = acp.el.input.beforeCursor();
10671
let query = acp.utils.getQuery(textBeforeCursor);
10772

73+
74+
// process query
75+
76+
const rawQuery = query;
77+
78+
if (langAcp.processQuery) {
79+
80+
query = langAcp.processQuery(query);
81+
82+
}
83+
84+
10885
// if query didn't change, return
10986
if (query === acp.curr.query) return;
11087

88+
// update query
11189
acp.curr.query = query;
11290

11391

@@ -117,9 +95,7 @@ acp.autocomplete = async (lang) => {
11795
if (query !== '') {
11896

11997
// autocomplete query
120-
results = acp.lang[lang].autocomplete(query);
121-
122-
query = acp.curr.query;
98+
results = acp.lang[lang].autocomplete(query, rawQuery);
12399

124100
}
125101

@@ -183,6 +159,7 @@ acp.autocomplete = async (lang) => {
183159
}
184160

185161

162+
186163
/*
187164
* Autocomplete Language Extension (acp language)
188165
* ----------------------------------------------
@@ -226,6 +203,30 @@ acp.autocomplete = async (lang) => {
226203
*/
227204

228205

206+
207+
acp.lang.css.init = () => {
208+
209+
let CSSProps = [];
210+
211+
CSSProps = Array.from(window.getComputedStyle(document.documentElement));
212+
213+
CSSProps.push('padding');
214+
CSSProps.push('margin');
215+
CSSProps.push('border');
216+
CSSProps.push('flex');
217+
CSSProps.push('grid');
218+
CSSProps.push('gap');
219+
CSSProps.push('background');
220+
CSSProps.push('overflow');
221+
CSSProps.push('transition');
222+
CSSProps.push('animation');
223+
CSSProps.push('-webkit-user-select');
224+
225+
acp.lang.css.props = CSSProps;
226+
227+
}
228+
229+
229230
acp.lang.css.autocomplete = (query) => {
230231

231232
let results = [];
@@ -252,19 +253,43 @@ acp.lang.css.autocomplete = (query) => {
252253
}
253254

254255

255-
acp.lang.js.autocomplete = (query) => {
256256

257-
let results = [];
257+
acp.lang.js.init = () => {
258+
259+
const iframe = document.createElement('iframe');
260+
261+
body.append(iframe);
262+
263+
acp.lang.js.props = iframe.contentWindow;
264+
265+
}
266+
267+
// add language alias / temp @@
268+
acp.lang.javascript = acp.lang.js;
269+
258270

271+
acp.lang.js.processQuery = (query) => {
272+
259273
// if query dosen't include a '.', return
260-
if (!query.includes('.')) return [];
274+
if (!query.includes('.')) return '';
261275

262276
// split query to get hierarchy
263-
hierarchy = query.split('.');
277+
let hierarchy = query.split('.');
264278

265-
// update query
266-
acp.curr.query = hierarchy[hierarchy.length - 1];
267-
query = acp.curr.query;
279+
// update query to last item in hierarchy
280+
const pQuery = hierarchy[hierarchy.length - 1];
281+
282+
return pQuery;
283+
284+
}
285+
286+
287+
acp.lang.js.autocomplete = (query, rawQuery) => {
288+
289+
let results = [];
290+
291+
// split query to get hierarchy
292+
let hierarchy = rawQuery.split('.');
268293

269294
// remove query from hierarchy
270295
hierarchy.pop();

0 commit comments

Comments
 (0)