@@ -21,7 +21,11 @@ import {
21
21
defaultHighlightStyle
22
22
} from '@codemirror/language' ;
23
23
import { highlightSelectionMatches } from '@codemirror/search' ;
24
- import { closeBrackets , closeBracketsKeymap } from '@codemirror/autocomplete' ;
24
+ import {
25
+ autocompletion ,
26
+ closeBrackets ,
27
+ closeBracketsKeymap
28
+ } from '@codemirror/autocomplete' ;
25
29
import {
26
30
defaultKeymap ,
27
31
history ,
@@ -36,7 +40,6 @@ import {
36
40
abbreviationTracker
37
41
} from '@emmetio/codemirror6-plugin' ;
38
42
39
- import { javascript } from '@codemirror/lang-javascript' ;
40
43
import { css } from '@codemirror/lang-css' ;
41
44
import { html } from '@codemirror/lang-html' ;
42
45
import { json } from '@codemirror/lang-json' ;
@@ -47,6 +50,7 @@ import { HTMLHint } from 'htmlhint';
47
50
import { CSSLint } from 'csslint' ;
48
51
import { emmetConfig } from '@emmetio/codemirror6-plugin' ;
49
52
53
+ import p5JavaScript from './p5JavaScript' ;
50
54
import tidyCodeWithPrettier from './tidier' ;
51
55
52
56
// ----- TODOS -----
@@ -83,7 +87,7 @@ function getFileLanguage(fileName) {
83
87
84
88
switch ( fileMode ) {
85
89
case 'javascript' :
86
- return javascript ;
90
+ return p5JavaScript ;
87
91
case 'css' :
88
92
return css ;
89
93
case 'html' :
@@ -255,6 +259,12 @@ function getFileEmmetConfig(fileName) {
255
259
const extraKeymaps = [ { key : 'Tab' , run : insertTab , shift : indentLess } ] ;
256
260
const emmetKeymaps = [ { key : 'Tab' , run : expandAbbreviation } ] ;
257
261
262
+ export const AUTOCOMPLETE_OPTIONS = {
263
+ tooltipClass : ( ) => 'CodeMirror-hints' ,
264
+ optionClass : ( ) => 'CodeMirror-hint' ,
265
+ closeOnBlur : false
266
+ } ;
267
+
258
268
/**
259
269
* Creates a new CodeMirror editor state with configurations,
260
270
* extensions, and keymaps tailored to the file type and settings.
@@ -265,13 +275,15 @@ export function createNewFileState(filename, document, settings) {
265
275
const {
266
276
linewrap,
267
277
lineNumbers,
278
+ autocomplete,
268
279
autocloseBracketsQuotes,
269
280
onUpdateLinting,
270
281
onViewUpdate
271
282
} = settings ;
272
283
const lineNumbersCpt = new Compartment ( ) ;
273
284
const lineWrappingCpt = new Compartment ( ) ;
274
285
const closeBracketsCpt = new Compartment ( ) ;
286
+ const autocompleteCpt = new Compartment ( ) ;
275
287
276
288
// Depending on the file mode, we have a different tidier function.
277
289
const mode = getFileMode ( filename ) ;
@@ -294,6 +306,9 @@ export function createNewFileState(filename, document, settings) {
294
306
lineNumbersCpt . of ( lineNumbers ? lineNumbersExt ( ) : [ ] ) ,
295
307
lineWrappingCpt . of ( linewrap ? EditorView . lineWrapping : [ ] ) ,
296
308
closeBracketsCpt . of ( autocloseBracketsQuotes ? closeBrackets ( ) : [ ] ) ,
309
+ autocompleteCpt . of (
310
+ autocomplete ? autocompletion ( AUTOCOMPLETE_OPTIONS ) : [ ]
311
+ ) ,
297
312
298
313
// Everything below here should always be on.
299
314
history ( ) ,
@@ -352,7 +367,13 @@ export function createNewFileState(filename, document, settings) {
352
367
}
353
368
354
369
const cmState = EditorState . create ( stateOptions ) ;
355
- return { cmState, lineNumbersCpt, lineWrappingCpt, closeBracketsCpt } ;
370
+ return {
371
+ cmState,
372
+ lineNumbersCpt,
373
+ lineWrappingCpt,
374
+ closeBracketsCpt,
375
+ autocompleteCpt
376
+ } ;
356
377
}
357
378
358
379
/**
0 commit comments