Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/node_modules/@stdlib/repl/lib/editor_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ function EditorActions( repl, ttyWrite ) {
// Cache a reference to the REPL keybindings:
this._keybindings = repl._keybindings;

// Cache a reference to the multiline handler:
this._multilineHandler = repl._multilineHandler;

return this;
}

Expand Down Expand Up @@ -170,6 +173,9 @@ setNonEnumerableReadOnly( EditorActions.prototype, '_modifyNextWord', function m
* @returns {void}
*/
setNonEnumerableReadOnly( EditorActions.prototype, 'moveRight', function moveRight() {
if ( this._multilineHandler && this._multilineHandler.moveRight() ) {
return;
}
this._ttyWrite.call( this._rli, null, {
'name': 'right'
});
Expand All @@ -184,6 +190,9 @@ setNonEnumerableReadOnly( EditorActions.prototype, 'moveRight', function moveRig
* @returns {void}
*/
setNonEnumerableReadOnly( EditorActions.prototype, 'moveLeft', function moveLeft() {
if ( this._multilineHandler && this._multilineHandler.moveLeft() ) {
return;
}
this._ttyWrite.call( this._rli, null, {
'name': 'left'
});
Expand Down Expand Up @@ -308,6 +317,9 @@ setNonEnumerableReadOnly( EditorActions.prototype, 'indentLineLeft', function in
* @returns {void}
*/
setNonEnumerableReadOnly( EditorActions.prototype, 'deleteLeft', function deleteLeft() {
if ( this._multilineHandler && this._multilineHandler.deleteLeft() ) {
return;
}
this._ttyWrite.call( this._rli, null, {
'name': 'backspace'
});
Expand Down
4 changes: 2 additions & 2 deletions lib/node_modules/@stdlib/repl/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,6 @@ function REPL( options ) {
}
self._autoCloser.beforeKeypress( data, key );
completed = self._previewCompleter.beforeKeypress( data, key );
FLG = self._editorActions.beforeKeypress( data, key );
self._eagerEvaluator.beforeKeypress( data, key );

// If ENTER keypress is encountered or if a preview was completed while navigating, gracefully close the completer...
if ( completed || ( key && key.name === 'return' ) ) {
Expand All @@ -390,6 +388,8 @@ function REPL( options ) {
self._completerEngine.beforeKeypress( data, key );
return;
}
FLG = self._editorActions.beforeKeypress( data, key );
self._eagerEvaluator.beforeKeypress( data, key );
// If completion was auto-completed or an action was triggered, don't trigger multi-line keybindings to avoid double operations...
if ( !completed && !FLG ) {
self._multilineHandler.beforeKeypress( data, key );
Expand Down
105 changes: 75 additions & 30 deletions lib/node_modules/@stdlib/repl/lib/multiline_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,78 @@ setNonEnumerableReadOnly( MultilineHandler.prototype, 'onKeypress', function onK
}
});

/**
* Moves the cursor to the previous line if at the beginning of the current line in multi-line mode.
*
* @name moveLeft
* @memberof MultilineHandler.prototype
* @type {Function}
* @returns {boolean} boolean indicating whether the cursor moved to the previous line
*/
setNonEnumerableReadOnly( MultilineHandler.prototype, 'moveLeft', function moveLeft() {
if ( this._history.index !== 0 ) {
// Reset current history cycle:
this._resetHistoryBuffers();
}
// If at the beginning of the line, move up to the previous line:
if ( this._rli.cursor === 0 && this._lineIndex > 0 ) {
this._moveLeft();
if ( this._multiline.active ) {
this._renderLines();
}
return true;
}
return false;
});

/**
* Moves the cursor to the next line if at the end of the current line in multi-line mode.
*
* @name moveRight
* @memberof MultilineHandler.prototype
* @type {Function}
* @returns {boolean} boolean indicating whether the cursor moved to the next line
*/
setNonEnumerableReadOnly( MultilineHandler.prototype, 'moveRight', function moveRight() {
if ( this._history.index !== 0 ) {
// Reset current history cycle:
this._resetHistoryBuffers();
}
// If at the end of the line, move to the next line:
if ( this._rli.cursor === this._rli.line.length && this._lineIndex < this._lines.length - 1 ) {
this._moveRight();
if ( this._multiline.active ) {
this._renderLines();
}
return true;
}
return false;
});

/**
* Simulates a backspace across line boundaries if at the beginning of the current line in multi-line mode.
*
* @name deleteLeft
* @memberof MultilineHandler.prototype
* @type {Function}
* @returns {boolean} boolean indicating whether the current line was removed and merged into the previous line
*/
setNonEnumerableReadOnly( MultilineHandler.prototype, 'deleteLeft', function deleteLeft() {
if ( this._history.index !== 0 ) {
// Reset current history cycle:
this._resetHistoryBuffers();
}
// If at the beginning of the line, remove and move up to the previous line:
if ( this._rli.cursor === 0 && this._lineIndex > 0 ) {
this._backspace();
if ( this._multiline.active ) {
this._renderLines();
}
return true;
}
return false;
});

/**
* Callback which should be invoked **before** a "keypress" event is processed by a readline interface.
*
Expand Down Expand Up @@ -766,46 +838,19 @@ setNonEnumerableReadOnly( MultilineHandler.prototype, 'beforeKeypress', function
}
break;
case 'left':
if ( this._history.index !== 0 ) {
// Reset current history cycle:
this._resetHistoryBuffers();
}
// If at the beginning of the line, move up to the previous line; otherwise, trigger default behavior...
if ( this._rli.cursor === 0 ) {
this._moveLeft();
if ( this._multiline.active ) {
this._renderLines();
}
if ( this.moveLeft() ) {
return;
}
this._ttyWrite.call( this._rli, data, key );
break;
case 'right':
if ( this._history.index !== 0 ) {
// Reset current history cycle:
this._resetHistoryBuffers();
}
// If at the end of the line, move up to the next line; otherwise, trigger default behavior...
if ( this._rli.cursor === this._rli.line.length ) {
this._moveRight();
if ( this._multiline.active ) {
this._renderLines();
}
if ( this.moveRight() ) {
return;
}
this._ttyWrite.call( this._rli, data, key );
break;
case 'backspace':
if ( this._history.index !== 0 ) {
// Reset current history cycle:
this._resetHistoryBuffers();
}
// If at the beginning of the line, remove and move up to the previous line; otherwise, trigger default behavior...
if ( this._rli.cursor === 0 ) {
this._backspace();
if ( this._multiline.active ) {
this._renderLines();
}
if ( this.deleteLeft() ) {
return;
}
this._ttyWrite.call( this._rli, data, key );
Expand Down
Loading
Loading