@@ -153,7 +153,7 @@ define(function(){
153
153
return - 1 ;
154
154
}
155
155
156
- function getTokenBounds ( buf , cursor ) {
156
+ function getTokenBounds ( buf , cursor , editor ) {
157
157
if ( cursor > buf . length ) {
158
158
throw new Error ( "Position " + cursor + " does not exist in code snippet <" + buf + ">" ) ;
159
159
}
@@ -174,7 +174,9 @@ define(function(){
174
174
tokenBeforeCursor : buf . substring ( start , cursor ) ,
175
175
after : buf . substring ( end , buf . length ) ,
176
176
start : start ,
177
- end : end
177
+ end : end ,
178
+ posStart : editor . posFromIndex ( start ) ,
179
+ posEnd : editor . posFromIndex ( end )
178
180
}
179
181
}
180
182
@@ -211,7 +213,7 @@ define(function(){
211
213
cursor_pos = utils . js_idx_to_char_idx ( cursor_pos , text ) ;
212
214
213
215
var prevBounds = this . tokenBounds ;
214
- var bounds = getTokenBounds ( text , cursor_pos ) ;
216
+ var bounds = getTokenBounds ( text , cursor_pos , this . editor ) ;
215
217
this . tokenBounds = bounds ;
216
218
if ( prevBounds && this . raw_result ) {
217
219
if ( bounds . before === prevBounds . before &&
@@ -223,6 +225,10 @@ define(function(){
223
225
if ( displayName [ 0 ] === '`' )
224
226
displayName = displayName . substring ( 1 , displayName . length - 1 ) ;
225
227
return displayName . startsWith ( bounds . tokenBeforeCursor )
228
+ } ) . map ( ( completion ) => {
229
+ completion . from = bounds . posStart ;
230
+ completion . to = bounds . posEnd ;
231
+ return completion ;
226
232
} ) ;
227
233
228
234
if ( newResult . length > 0 ) {
@@ -542,7 +548,7 @@ define(function(){
542
548
var optionsLen ;
543
549
var index ;
544
550
var prevIndex ;
545
- if ( code == keycodes . enter ) {
551
+ if ( code == keycodes . enter && ! event . shiftKey ) {
546
552
event . codemirrorIgnore = true ;
547
553
event . _ipkmIgnore = true ;
548
554
event . preventDefault ( ) ;
@@ -608,7 +614,7 @@ define(function(){
608
614
} ;
609
615
610
616
function _isCompletionKey ( key ) {
611
- return key . length === 1 ;
617
+ return / ^ [ A - Z 0 - 9 . : " ] $ / i . test ( key ) ;
612
618
}
613
619
614
620
Completer . prototype . keypress = function ( event ) {
@@ -675,12 +681,16 @@ define(function(){
675
681
. forEach ( it => it . clear ( ) ) ;
676
682
}
677
683
678
- CodeCell . prototype . _handle_change = function ( cm , changes ) {
679
- this . notebook . get_cells ( ) . forEach ( ( cell ) => {
684
+ function clearAllErrors ( notebook ) {
685
+ notebook . get_cells ( ) . forEach ( ( cell ) => {
680
686
if ( cell . code_mirror ) {
681
687
clearErrors ( cell . code_mirror ) ;
682
688
}
683
689
} ) ;
690
+ }
691
+
692
+ CodeCell . prototype . _handle_change = function ( cm , changes ) {
693
+ clearAllErrors ( this . notebook ) ;
684
694
this . kernel . listErrors ( cm . getValue ( ) , ( msg ) => {
685
695
var content = msg . content ;
686
696
console . log ( content ) ;
@@ -832,6 +842,7 @@ define(function(){
832
842
} ;
833
843
834
844
CodeCell . prototype . _handle_execute_reply = function ( msg ) {
845
+ clearAllErrors ( this . notebook )
835
846
this . bindEvents ( ) ;
836
847
837
848
this . set_input_prompt ( msg . content . execution_count ) ;
0 commit comments