@@ -63,6 +63,7 @@ var inputPrompt = require( './input_prompt.js' );
63
63
var OutputStream = require ( './output_stream.js' ) ;
64
64
var processLine = require ( './process_line.js' ) ;
65
65
var completerFactory = require ( './completer.js' ) ;
66
+ var MultilineHandler = require ( './multiline_handler.js' ) ;
66
67
var PreviewCompleter = require ( './completer_preview.js' ) ;
67
68
var AutoCloser = require ( './auto_close_pairs.js' ) ;
68
69
var SyntaxHighlighter = require ( './syntax_highlighter.js' ) ;
@@ -241,6 +242,9 @@ function REPL( options ) {
241
242
setNonEnumerable ( this , '_multiline' , { } ) ;
242
243
setNonEnumerable ( this . _multiline , 'active' , false ) ;
243
244
setNonEnumerable ( this . _multiline , 'mode' , 'incomplete_expression' ) ;
245
+ setNonEnumerable ( this . _multiline , 'line' , 0 ) ;
246
+ setNonEnumerable ( this . _multiline , 'lines' , [ ] ) ;
247
+ setNonEnumerable ( this . _multiline , 'buffer' , '' ) ;
244
248
245
249
// Initialize an internal flag indicating whether the REPL has been closed:
246
250
setNonEnumerable ( this , '_closed' , false ) ;
@@ -273,6 +277,9 @@ function REPL( options ) {
273
277
'completer' : this . _completer
274
278
} ) ) ;
275
279
280
+ // Initialize a multiline handler:
281
+ setNonEnumerableReadOnly ( this , '_multilineHandler' , new MultilineHandler ( this , this . _rli . _ttyWrite ) ) ;
282
+
276
283
// Create a new auto-closer:
277
284
setNonEnumerableReadOnly ( this , '_autoCloser' , new AutoCloser ( this . _rli , this . _settings . autoClosePairs , this . _settings . autoDeletePairs ) ) ;
278
285
@@ -337,12 +344,20 @@ function REPL( options ) {
337
344
* @param {(Object|void) } key - key object
338
345
*/
339
346
function beforeKeypress ( data , key ) {
347
+ var completed ;
348
+
340
349
if ( self . _ostream . isPaging ) {
341
350
self . _ostream . beforeKeypress ( data , key ) ;
342
351
return ;
343
352
}
344
353
self . _autoCloser . beforeKeypress ( data , key ) ;
345
- self . _previewCompleter . beforeKeypress ( data , key ) ;
354
+ completed = self . _previewCompleter . beforeKeypress ( data , key ) ;
355
+
356
+ // If completion was auto-completed, don't trigger multiline keybindings to avoid double operations...
357
+ if ( ! completed && self . _multiline . active ) {
358
+ self . _multilineHandler . beforeKeypress ( data , key ) ;
359
+ return ;
360
+ }
346
361
self . _ttyWrite . call ( self . _rli , data , key ) ;
347
362
}
348
363
@@ -366,6 +381,7 @@ function REPL( options ) {
366
381
if ( autoClosed ) {
367
382
self . _previewCompleter . clear ( ) ;
368
383
}
384
+ self . _multilineHandler . onKeypress ( data , key ) ;
369
385
self . _syntaxHighlighter . onKeypress ( ) ;
370
386
self . _previewCompleter . onKeypress ( data , key ) ;
371
387
}
@@ -508,6 +524,19 @@ setNonEnumerableReadOnly( REPL.prototype, '_prompt', function prompt() {
508
524
return inputPrompt ( this . _inputPrompt , this . _count ) ;
509
525
} ) ;
510
526
527
+ /**
528
+ * Returns the height of the current input.
529
+ *
530
+ * @private
531
+ * @name _inputHeight
532
+ * @memberof REPL.prototype
533
+ * @type {Function }
534
+ * @returns {number } input rows
535
+ */
536
+ setNonEnumerableReadOnly ( REPL . prototype , '_inputHeight' , function inputHeight ( ) {
537
+ return this . _multiline . lines . length ;
538
+ } ) ;
539
+
511
540
/**
512
541
* Returns the REPL viewport.
513
542
*
0 commit comments