3
3
import PropTypes from 'prop-types' ;
4
4
import React from 'react' ;
5
5
import CodeMirror from 'codemirror' ;
6
- import Fuse from 'fuse.js' ;
7
6
import emmet from '@emmetio/codemirror-plugin' ;
8
7
import prettier from 'prettier/standalone' ;
9
8
import babelParser from 'prettier/parser-babel' ;
@@ -33,12 +32,8 @@ import 'codemirror/addon/search/jump-to-line';
33
32
import 'codemirror/addon/edit/matchbrackets' ;
34
33
import 'codemirror/addon/edit/closebrackets' ;
35
34
import 'codemirror/addon/selection/mark-selection' ;
36
- import 'codemirror/addon/hint/css-hint' ;
37
35
import 'codemirror-colorpicker' ;
38
36
39
- import { JSHINT } from 'jshint' ;
40
- import { CSSLint } from 'csslint' ;
41
- import { HTMLHint } from 'htmlhint' ;
42
37
import classNames from 'classnames' ;
43
38
import { debounce } from 'lodash' ;
44
39
import { connect } from 'react-redux' ;
@@ -47,8 +42,6 @@ import MediaQuery from 'react-responsive';
47
42
import '../../../../utils/htmlmixed' ;
48
43
import '../../../../utils/p5-javascript' ;
49
44
import { metaKey } from '../../../../utils/metaKey' ;
50
- import '../show-hint' ;
51
- import * as hinter from '../../../../utils/p5-hinter' ;
52
45
import '../../../../utils/codemirror-search' ;
53
46
54
47
import beepUrl from '../../../../sounds/audioAlert.mp3' ;
@@ -73,11 +66,9 @@ import { EditorContainer, EditorHolder } from './MobileEditor';
73
66
import { FolderIcon } from '../../../../common/icons' ;
74
67
import IconButton from '../../../../common/IconButton' ;
75
68
76
- emmet ( CodeMirror ) ;
69
+ import { showHint , hideHinter } from './hinter' ;
77
70
78
- window . JSHINT = JSHINT ;
79
- window . CSSLint = CSSLint ;
80
- window . HTMLHint = HTMLHint ;
71
+ emmet ( CodeMirror ) ;
81
72
82
73
const INDENTATION_AMOUNT = 2 ;
83
74
@@ -146,11 +137,6 @@ class Editor extends React.Component {
146
137
}
147
138
} ) ;
148
139
149
- this . hinter = new Fuse ( hinter . p5Hinter , {
150
- threshold : 0.05 ,
151
- keys : [ 'text' ]
152
- } ) ;
153
-
154
140
delete this . _cm . options . lint . options . errors ;
155
141
156
142
const replaceCommand =
@@ -207,7 +193,7 @@ class Editor extends React.Component {
207
193
// Show hint
208
194
const mode = this . _cm . getOption ( 'mode' ) ;
209
195
if ( / ^ [ a - z ] $ / i. test ( e . key ) && ( mode === 'css' || mode === 'javascript' ) ) {
210
- this . showHint ( _cm ) ;
196
+ showHint ( _cm , this . props . autocompleteHinter , this . props . fontSize ) ;
211
197
}
212
198
if ( e . key === 'Escape' ) {
213
199
e . preventDefault ( ) ;
@@ -283,7 +269,7 @@ class Editor extends React.Component {
283
269
if ( this . props . autocompleteHinter !== prevProps . autocompleteHinter ) {
284
270
if ( ! this . props . autocompleteHinter ) {
285
271
// close the hinter window once the preference is turned off
286
- CodeMirror . showHint ( this . _cm , ( ) => { } , { } ) ;
272
+ hideHinter ( this . _cm ) ;
287
273
}
288
274
}
289
275
@@ -378,99 +364,6 @@ class Editor extends React.Component {
378
364
this . _cm . execCommand ( 'findPersistent' ) ;
379
365
}
380
366
381
- showHint ( _cm ) {
382
- if ( ! this . props . autocompleteHinter ) {
383
- CodeMirror . showHint ( _cm , ( ) => { } , { } ) ;
384
- return ;
385
- }
386
-
387
- let focusedLinkElement = null ;
388
- const setFocusedLinkElement = ( set ) => {
389
- if ( set && ! focusedLinkElement ) {
390
- const activeItemLink = document . querySelector (
391
- `.CodeMirror-hint-active a`
392
- ) ;
393
- if ( activeItemLink ) {
394
- focusedLinkElement = activeItemLink ;
395
- focusedLinkElement . classList . add ( 'focused-hint-link' ) ;
396
- focusedLinkElement . parentElement . parentElement . classList . add (
397
- 'unfocused'
398
- ) ;
399
- }
400
- }
401
- } ;
402
- const removeFocusedLinkElement = ( ) => {
403
- if ( focusedLinkElement ) {
404
- focusedLinkElement . classList . remove ( 'focused-hint-link' ) ;
405
- focusedLinkElement . parentElement . parentElement . classList . remove (
406
- 'unfocused'
407
- ) ;
408
- focusedLinkElement = null ;
409
- return true ;
410
- }
411
- return false ;
412
- } ;
413
-
414
- const hintOptions = {
415
- _fontSize : this . props . fontSize ,
416
- completeSingle : false ,
417
- extraKeys : {
418
- 'Shift-Right' : ( cm , e ) => {
419
- const activeItemLink = document . querySelector (
420
- `.CodeMirror-hint-active a`
421
- ) ;
422
- if ( activeItemLink ) activeItemLink . click ( ) ;
423
- } ,
424
- Right : ( cm , e ) => {
425
- setFocusedLinkElement ( true ) ;
426
- } ,
427
- Left : ( cm , e ) => {
428
- removeFocusedLinkElement ( ) ;
429
- } ,
430
- Up : ( cm , e ) => {
431
- const onLink = removeFocusedLinkElement ( ) ;
432
- e . moveFocus ( - 1 ) ;
433
- setFocusedLinkElement ( onLink ) ;
434
- } ,
435
- Down : ( cm , e ) => {
436
- const onLink = removeFocusedLinkElement ( ) ;
437
- e . moveFocus ( 1 ) ;
438
- setFocusedLinkElement ( onLink ) ;
439
- } ,
440
- Enter : ( cm , e ) => {
441
- if ( focusedLinkElement ) focusedLinkElement . click ( ) ;
442
- else e . pick ( ) ;
443
- }
444
- } ,
445
- closeOnUnfocus : false
446
- } ;
447
-
448
- if ( _cm . options . mode === 'javascript' ) {
449
- // JavaScript
450
- CodeMirror . showHint (
451
- _cm ,
452
- ( ) => {
453
- const c = _cm . getCursor ( ) ;
454
- const token = _cm . getTokenAt ( c ) ;
455
-
456
- const hints = this . hinter
457
- . search ( token . string )
458
- . filter ( ( h ) => h . item . text [ 0 ] === token . string [ 0 ] ) ;
459
-
460
- return {
461
- list : hints ,
462
- from : CodeMirror . Pos ( c . line , token . start ) ,
463
- to : CodeMirror . Pos ( c . line , c . ch )
464
- } ;
465
- } ,
466
- hintOptions
467
- ) ;
468
- } else if ( _cm . options . mode === 'css' ) {
469
- // CSS
470
- CodeMirror . showHint ( _cm , CodeMirror . hint . css , hintOptions ) ;
471
- }
472
- }
473
-
474
367
showReplace ( ) {
475
368
this . _cm . execCommand ( 'replace' ) ;
476
369
}
0 commit comments