11
11
// The second function (inside) contains the actual implementation.
12
12
import parseCode from './parseCode' ;
13
13
import CodeMirror from 'codemirror' ;
14
+ import warnIfBlacklisted from './warn' ;
14
15
15
16
( function ( mod ) {
16
17
if ( typeof exports == 'object' && typeof module == 'object' )
@@ -32,7 +33,7 @@ import CodeMirror from 'codemirror';
32
33
// This is the old interface, kept around for now to stay
33
34
// backwards-compatible.
34
35
CodeMirror . showHint = function ( cm , getHints , options ) {
35
- console . log ( 'showhint was called: ' , getHints , options ) ;
36
+ console . log ( 'showhint was called: ' , cm , getHints , options ) ;
36
37
if ( ! getHints ) return cm . showHint ( options ) ; // if not getHints function passed, it assumes youre using the newer interface
37
38
// restructured options to call the new c.showHint() method
38
39
if ( options && options . async ) getHints . async = true ;
@@ -47,6 +48,7 @@ import CodeMirror from 'codemirror';
47
48
// this adds a method called showHint to every cm editor instance (editor.showHint())
48
49
CodeMirror . defineExtension ( 'showHint' , function ( options ) {
49
50
options = parseOptions ( this , this . getCursor ( 'start' ) , options ) ;
51
+ console . log ( 'options are: ' ) ;
50
52
var selections = this . listSelections ( ) ;
51
53
console . log ( 'selections are: ' , selections ) ;
52
54
if ( selections . length > 1 ) return ;
@@ -131,17 +133,27 @@ import CodeMirror from 'codemirror';
131
133
132
134
pick : function ( data , i ) {
133
135
// selects an item from the suggestion list
136
+ console . log ( 'data, i= ' , data , i ) ;
134
137
var completion = data . list [ i ] ,
135
138
self = this ;
139
+
136
140
this . cm . operation ( function ( ) {
137
- if ( completion . hint ) completion . hint ( self . cm , data , completion ) ;
138
- else
141
+ // this is how cm allows custom behavior per suggestion
142
+ // if hint is provided on a hint object, it will be called instead of the default replace range
143
+ const name = completion . item ?. text ;
144
+ if ( name ) warnIfBlacklisted ( self . cm , name ) ;
145
+
146
+ if ( completion . hint ) {
147
+ completion . hint ( self . cm , data , completion ) ;
148
+ } else {
149
+ console . log ( 'gettext(C)= ' , getText ( completion ) ) ;
139
150
self . cm . replaceRange (
140
151
getText ( completion ) ,
141
152
completion . from || data . from ,
142
153
completion . to || data . to ,
143
154
'complete'
144
155
) ;
156
+ }
145
157
// signals that a hint was picked and scrolls to it
146
158
CodeMirror . signal ( data , 'pick' , completion ) ;
147
159
self . cm . scrollIntoView ( ) ;
@@ -232,6 +244,7 @@ import CodeMirror from 'codemirror';
232
244
}
233
245
// extracts the visible text from a completion entry
234
246
function getText ( completion ) {
247
+ console . log ( 'gettext called' ) ;
235
248
if ( typeof completion === 'string' ) return completion ;
236
249
else return completion . item . text ;
237
250
}
328
341
} </p>`;
329
342
}
330
343
331
- function getInlineHintSuggestion ( focus , tokenLength ) {
332
- console . log ( 'the focus is: ' , focus , tokenLength ) ;
344
+ function getInlineHintSuggestion ( cm , focus , tokenLength ) {
345
+ const name = focus . item ?. text ;
346
+ console . log ( 'the focus is: ' , focus , name ) ;
347
+ if ( name ) warnIfBlacklisted ( cm , name ) ;
333
348
const suggestionItem = focus . item ;
334
349
// builds the remainder of the suggestion excluding what user already typed
335
350
const baseCompletion = `<span class="inline-hinter-suggestion">${ suggestionItem . text . slice (
365
380
366
381
if ( token && focus . item ) {
367
382
const suggestionHTML = getInlineHintSuggestion (
383
+ cm ,
368
384
focus ,
369
385
token . string . length
370
386
) ;
380
396
}
381
397
}
382
398
383
- // defines the autocomplete dropdown ui
384
- // completition = the autocomplete context having cm and options
399
+ // defines the autocomplete dropdown ui; renders the suggestions
400
+ // completion = the autocomplete context having cm and options
385
401
// data = object with the list of suggestions
386
402
function Widget ( completion , data ) {
387
403
console . log ( 'widget completetition= ' , completion ) ;
409
425
changeInlineHint ( cm , data . list [ this . selectedHint ] ) ;
410
426
411
427
var completions = data . list ;
412
-
413
428
for ( var i = 0 ; i < completions . length ; ++ i ) {
414
429
var elt = hints . appendChild ( ownerDocument . createElement ( 'li' ) ) ,
415
430
cur = completions [ i ] ;
427
442
const name = getText ( cur ) ;
428
443
429
444
if ( cur . item && cur . item . type ) {
445
+ console . log ( 'display hint calllllled' ) ;
430
446
cur . displayText = displayHint ( name , cur . item . type , cur . item . p5 ) ;
431
447
}
432
448
0 commit comments