Skip to content
Closed
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
52 changes: 32 additions & 20 deletions zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,19 @@ angular.module('zeppelinWebApp').controller('ParagraphCtrl', function($scope, $r
$scope.editor.commands.bindKey('ctrl-.', 'startAutocomplete');
$scope.editor.commands.bindKey('ctrl-space', null);

var keyBindingEditorFocusAction = function(scrollValue) {
var numRows = $scope.editor.getSession().getLength();
var currentRow = $scope.editor.getCursorPosition().row;
if (currentRow === 0 && scrollValue <= 0) {
// move focus to previous paragraph
$scope.$emit('moveFocusToPreviousParagraph', $scope.paragraph.id);
} else if (currentRow === numRows - 1 && scrollValue >= 0) {
$scope.$emit('moveFocusToNextParagraph', $scope.paragraph.id);
} else {
$scope.scrollToCursor($scope.paragraph.id, scrollValue);
}
};

// handle cursor moves
$scope.editor.keyBinding.origOnCommandKey = $scope.editor.keyBinding.onCommandKey;
$scope.editor.keyBinding.onCommandKey = function(e, hashId, keyCode) {
Expand All @@ -678,27 +691,26 @@ angular.module('zeppelinWebApp').controller('ParagraphCtrl', function($scope, $r
angular.element('#' + $scope.paragraph.id + '_editor > textarea').css('top', cursorPos.top);
}

var numRows;
var currentRow;
var ROW_UP = -1;
var ROW_DOWN = 1;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forgot this case in your function above

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@corneadoug
Thanks Giving find.
I will fix.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@corneadoug
Modifications completed.

if (currentRow === 0 || (currentRow === numRows - 1)) {

if (keyCode === 38 || (keyCode === 80 && e.ctrlKey && !e.altKey)) { // UP
numRows = $scope.editor.getSession().getLength();
currentRow = $scope.editor.getCursorPosition().row;
if (currentRow === 0) {
// move focus to previous paragraph
$scope.$emit('moveFocusToPreviousParagraph', $scope.paragraph.id);
} else {
$scope.scrollToCursor($scope.paragraph.id, -1);
}
} else if (keyCode === 40 || (keyCode === 78 && e.ctrlKey && !e.altKey)) { // DOWN
numRows = $scope.editor.getSession().getLength();
currentRow = $scope.editor.getCursorPosition().row;
if (currentRow === numRows - 1) {
// move focus to next paragraph
$scope.$emit('moveFocusToNextParagraph', $scope.paragraph.id);
} else {
$scope.scrollToCursor($scope.paragraph.id, 1);
}
switch (keyCode) {
case 38:
keyBindingEditorFocusAction(ROW_UP);
break;
case 80:
if (e.ctrlKey && !e.altKey) {
keyBindingEditorFocusAction(ROW_UP);
}
break;
case 40:
keyBindingEditorFocusAction(ROW_DOWN);
break;
case 78:
if (e.ctrlKey && !e.altKey) {
keyBindingEditorFocusAction(ROW_DOWN);
}
break;
}
}
this.origOnCommandKey(e, hashId, keyCode);
Expand Down