Repository: incubator-zeppelin
Updated Branches:
  refs/heads/master a6187df25 -> 5951e6102


ZEPPELIN-467 Fix ace editor focusing problem in chrome

This PR addresses https://issues.apache.org/jira/browse/ZEPPELIN-467

When (invisible) textarea position is not correctly placed(this problem occur 
in Chrome when contents in editor is long), place it in cursor position of ace 
editor. not always set to 0.

This PR also includes scrolling animation improvement. Make animation faster 
(duration 200 -> 100ms), and cancel animation before new animation starts.

Author: Lee moon soo <[email protected]>

Closes #482 from Leemoonsoo/ZEPPELIN-467 and squashes the following commits:

434b5b2 [Lee moon soo] Avoid repeating angular.element('body')
04ba168 [Lee moon soo] Fix ace editor focusing problem


Project: http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/commit/5951e610
Tree: http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/tree/5951e610
Diff: http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/diff/5951e610

Branch: refs/heads/master
Commit: 5951e6102b37e79140430ac6c1eabd6c0c29491c
Parents: a6187df
Author: Lee moon soo <[email protected]>
Authored: Fri Nov 27 15:53:28 2015 +0900
Committer: Lee moon soo <[email protected]>
Committed: Sun Nov 29 07:48:36 2015 +0900

----------------------------------------------------------------------
 .../notebook/paragraph/paragraph.controller.js  | 22 ++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/5951e610/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js
----------------------------------------------------------------------
diff --git a/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js 
b/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js
index 430c5ac..18a47a5 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,14 @@ angular.module('zeppelinWebApp')
         scrollTargetPos = documentHeight;
       }
     }
-    angular.element('body').scrollTo(scrollTargetPos, {axis: 'y', interrupt: 
true, duration:200});
+
+    // 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) {
@@ -752,11 +763,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);
     }

Reply via email to