From 04ba168acfcd87ac68b2788d0b3cbf60c0c7d65a Mon Sep 17 00:00:00 2001 From: Lee moon soo Date: Thu, 26 Nov 2015 22:44:34 +0900 Subject: [PATCH 1/2] Fix ace editor focusing problem --- .../notebook/paragraph/paragraph.controller.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js b/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js index 430c5ac5f05..cd17fa3ea0b 100644 --- a/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js +++ b/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js @@ -615,7 +615,11 @@ angular.module('zeppelinWebApp') if ($scope.editor.completer && $scope.editor.completer.activated) { // if autocompleter is active } else { // fix ace editor focus issue in chrome (textarea element goes to top: -1000px after focused by cursor move) - angular.element('#' + $scope.paragraph.id + '_editor > textarea').css('top', 0); + if (parseInt(angular.element('#' + $scope.paragraph.id + '_editor > textarea').css('top').replace('px', '')) < 0) { + var position = $scope.editor.getCursorPosition(); + var cursorPos = $scope.editor.renderer.$cursorLayer.getPixelPosition(position, true); + angular.element('#' + $scope.paragraph.id + '_editor > textarea').css('top', cursorPos.top); + } var numRows; var currentRow; @@ -683,7 +687,7 @@ angular.module('zeppelinWebApp') var position = $scope.editor.getCursorPosition(); var lastCursorPosition = $scope.editor.renderer.$cursorLayer.getPixelPosition(position, true); - var calculatedCursorPosition = editorPosition.top + lastCursorPosition.top + 16*lastCursorMove; + var calculatedCursorPosition = editorPosition.top + lastCursorPosition.top + lineHeight*lastCursorMove; var scrollTargetPos; if (calculatedCursorPosition < scrollPosition + headerHeight + scrollTriggerEdgeMargin) { @@ -698,7 +702,9 @@ angular.module('zeppelinWebApp') scrollTargetPos = documentHeight; } } - angular.element('body').scrollTo(scrollTargetPos, {axis: 'y', interrupt: true, duration:200}); + angular.element('body').stop(); + angular.element('body').finish(); + angular.element('body').scrollTo(scrollTargetPos, {axis: 'y', interrupt: true, duration:100}); }; var setEditorHeight = function(id, height) { @@ -752,11 +758,10 @@ angular.module('zeppelinWebApp') var row; if (cursorPos >= 0) { row = cursorPos; - var column = 0; $scope.editor.gotoLine(row, 0); } else { - row = $scope.editor.session.getLength() - 1; - $scope.editor.gotoLine(row + 1, 0); + row = $scope.editor.session.getLength(); + $scope.editor.gotoLine(row, 0); } $scope.scrollToCursor($scope.paragraph.id, 0); } From 434b5b287750e0b1bb5042b18e26e91df8c32217 Mon Sep 17 00:00:00 2001 From: Lee moon soo Date: Fri, 27 Nov 2015 15:53:28 +0900 Subject: [PATCH 2/2] Avoid repeating angular.element('body') --- .../app/notebook/paragraph/paragraph.controller.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js b/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js index cd17fa3ea0b..18a47a52bab 100644 --- a/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js +++ b/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js @@ -702,9 +702,14 @@ angular.module('zeppelinWebApp') scrollTargetPos = documentHeight; } } - angular.element('body').stop(); - angular.element('body').finish(); - angular.element('body').scrollTo(scrollTargetPos, {axis: 'y', interrupt: true, duration:100}); + + // cancel previous scroll animation + var bodyEl = angular.element('body'); + bodyEl.stop(); + bodyEl.finish(); + + // scroll to scrollTargetPos + bodyEl.scrollTo(scrollTargetPos, {axis: 'y', interrupt: true, duration:100}); }; var setEditorHeight = function(id, height) {