Repository: zeppelin
Updated Branches:
  refs/heads/master d5a3c7444 -> 84cb4b5fb


ZEPPELIN-277 Add Tab as Autocomplete for Notebook non-md paragraphs

### What is this PR for?
This PR will add tab as auto complete invoker if paragraph is non-md and user 
has not pressed the tab as a first character in the line

### What type of PR is it?
[Improvement]

### What is the Jira issue?
* https://issues.apache.org/jira/browse/ZEPPELIN-277
* https://issues.apache.org/jira/browse/ZEPPELIN-2736

### How should this be tested?

- Build: mvn clean package -Denforcer.skip -DskipTests -Drat.skip
- Open a paragraph
- Press tab with following options: first character, after space

### Questions:
* Does the licenses files need an update? no
* Is there breaking changes for older versions? no
* Does this needs documentation? no

Author: Malay Majithia <malay.majit...@gmail.com>
Author: Lee moon soo <m...@apache.org>

Closes #2542 from malayhm/ZEPPELIN-277 and squashes the following commits:

436f22d [Malay Majithia] Added Tab auto completion flag for python sql and r
b37e084 [Malay Majithia] Fixed lint error
18fc814 [Malay Majithia] Merge branch 'master' into ZEPPELIN-277
b09730e [Malay Majithia] Merge branch 'master' into ZEPPELIN-277
63d69e1 [Malay Majithia] Merge branch 'ZEPPELIN-277' of 
github.com:malayhm/zeppelin into ZEPPELIN-277
a75f0fe [Malay Majithia] Improved the first character check logic
2ec879d [Malay Majithia] Merge pull request #1 from 
Leemoonsoo/ZEPPELIN-277-completion-key
77afdba [Lee moon soo] fix style
77b47b6 [Malay Majithia] If all the previous line characters are tab, don't 
show autocomplete on tab
46f612a [Malay Majithia] ZEPPELIN-277 Add Tab as Autocomplete for Notebook 
non-md paragraphs
865c0a6 [Lee moon soo] Set python and spark interpreter completionKey
05d5860 [Lee moon soo] Update doc
973068b [Lee moon soo] apply tab completion based on editor.completionKey
5f4d81c [Malay Majithia] If all the previous line characters are tab, don't 
show autocomplete on tab
655ba88 [Malay Majithia] ZEPPELIN-277 Add Tab as Autocomplete for Notebook 
non-md paragraphs


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

Branch: refs/heads/master
Commit: 84cb4b5fb9b7c19bbaac367f8d833ef66a06b0f0
Parents: d5a3c74
Author: Malay Majithia <malay.majit...@gmail.com>
Authored: Wed Oct 18 14:37:59 2017 +0530
Committer: Lee moon soo <m...@apache.org>
Committed: Wed Oct 18 02:12:19 2017 -0700

----------------------------------------------------------------------
 .../development/writing_zeppelin_interpreter.md | 16 +++++++++-
 .../src/main/resources/interpreter-setting.json |  6 ++--
 r/src/main/resources/interpreter-setting.json   |  5 +++
 .../src/main/resources/interpreter-setting.json | 12 +++++---
 .../notebook/paragraph/paragraph.controller.js  | 32 ++++++++++++++++++++
 5 files changed, 64 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/84cb4b5f/docs/development/writing_zeppelin_interpreter.md
----------------------------------------------------------------------
diff --git a/docs/development/writing_zeppelin_interpreter.md 
b/docs/development/writing_zeppelin_interpreter.md
index f4c0bc9..f62e97e 100644
--- a/docs/development/writing_zeppelin_interpreter.md
+++ b/docs/development/writing_zeppelin_interpreter.md
@@ -116,7 +116,8 @@ Here is an example of `interpreter-setting.json` on your 
own interpreter.
     },
     "editor": {
       "language": "your-syntax-highlight-language",
-      "editOnDblClick": false
+      "editOnDblClick": false,
+      "completionKey": "TAB"
     }
   },
   {
@@ -170,6 +171,19 @@ If your interpreter uses mark-up language such as markdown 
or HTML, set `editOnD
   "editOnDblClick": false
 }
 ```
+
+### Completion key (Optional)
+By default, `Ctrl+dot(.)` brings autocompletion list in the editor.
+Through `completionKey`, each interpreter can configure autocompletion key.
+Currently `TAB` is only available option.
+
+```
+"editor": {
+  "completionKey": "TAB"
+}
+```
+
+
 ## Install your interpreter binary
 
 Once you have built your interpreter, you can place it under the interpreter 
directory with all its dependencies.

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/84cb4b5f/python/src/main/resources/interpreter-setting.json
----------------------------------------------------------------------
diff --git a/python/src/main/resources/interpreter-setting.json 
b/python/src/main/resources/interpreter-setting.json
index bc1a746..d6b3538 100644
--- a/python/src/main/resources/interpreter-setting.json
+++ b/python/src/main/resources/interpreter-setting.json
@@ -44,7 +44,8 @@
     },
     "editor": {
       "language": "python",
-      "editOnDblClick": false
+      "editOnDblClick": false,
+      "completionKey": "TAB"
     }
   },
   {
@@ -55,7 +56,8 @@
     },
     "editor":{
       "language": "sql",
-      "editOnDblClick": false
+      "editOnDblClick": false,
+      "completionKey": "TAB"
     }
   },
   {

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/84cb4b5f/r/src/main/resources/interpreter-setting.json
----------------------------------------------------------------------
diff --git a/r/src/main/resources/interpreter-setting.json 
b/r/src/main/resources/interpreter-setting.json
index b7dcaf7..c5997a3 100644
--- a/r/src/main/resources/interpreter-setting.json
+++ b/r/src/main/resources/interpreter-setting.json
@@ -24,6 +24,11 @@
         "defaultValue": "60",
         "type": "number"
       }
+    },
+    "editor": {
+      "language": "r",
+      "editOnDblClick": false,
+      "completionKey": "TAB"
     }
   },
   {

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/84cb4b5f/spark/src/main/resources/interpreter-setting.json
----------------------------------------------------------------------
diff --git a/spark/src/main/resources/interpreter-setting.json 
b/spark/src/main/resources/interpreter-setting.json
index 7c13c49..4aeda6c 100644
--- a/spark/src/main/resources/interpreter-setting.json
+++ b/spark/src/main/resources/interpreter-setting.json
@@ -71,7 +71,8 @@
     },
     "editor": {
       "language": "scala",
-      "editOnDblClick": false
+      "editOnDblClick": false,
+      "completionKey": "TAB"
     }
   },
   {
@@ -110,7 +111,8 @@
     },
     "editor": {
       "language": "sql",
-      "editOnDblClick": false
+      "editOnDblClick": false,
+      "completionKey": "TAB"
     }
   },
   {
@@ -135,7 +137,8 @@
     },
     "editor": {
       "language": "scala",
-      "editOnDblClick": false
+      "editOnDblClick": false,
+      "completionKey": "TAB"
     }
   },
   {
@@ -160,7 +163,8 @@
     },
     "editor": {
       "language": "python",
-      "editOnDblClick": false
+      "editOnDblClick": false,
+      "completionKey": "TAB"
     }
   },
   {

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/84cb4b5f/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 edc808f..7d95d3b 100644
--- a/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js
+++ b/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js
@@ -185,6 +185,11 @@ function ParagraphCtrl ($scope, $rootScope, $route, 
$window, $routeParams, $loca
     }
   }
 
+  const isTabCompletion = function() {
+    const completionKey = $scope.paragraph.config.editorSetting.completionKey
+    return completionKey === 'TAB'
+  }
+
   $scope.$on('updateParagraphOutput', function (event, data) {
     if ($scope.paragraph.id === data.paragraphId) {
       if (!$scope.paragraph.results) {
@@ -851,6 +856,33 @@ function ParagraphCtrl ($scope, $rootScope, $route, 
$window, $routeParams, $loca
       // autocomplete on 'ctrl+.'
       $scope.editor.commands.bindKey('ctrl-.', 'startAutocomplete')
 
+      // Show autocomplete on tab
+      $scope.editor.commands.addCommand({
+        name: 'tabAutocomplete',
+        bindKey: {
+          win: 'tab',
+          mac: 'tab',
+          sender: 'editor|cli'
+        },
+        exec: function(env, args, request) {
+          let iCursor = $scope.editor.getCursorPosition()
+          let currentLine = $scope.editor.session.getLine(iCursor.row)
+          let isAllTabs = currentLine.substring(0, iCursor.column - 
1).split('').every(function(char) {
+            return (char === '\t' || char === ' ')
+          })
+
+          // If user has pressed tab on first line char or if 
isTabCompletion() is false, keep existing behavior
+          // If user has pressed tab anywhere in between and editor mode is 
not %md, show autocomplete
+          if (!isAllTabs && iCursor.column && isTabCompletion()) {
+            $scope.editor.execCommand('startAutocomplete')
+          } else {
+            ace.config.loadModule('ace/ext/language_tools', function () {
+              $scope.editor.insertSnippet('\t')
+            })
+          }
+        }
+      })
+
       let keyBindingEditorFocusAction = function (scrollValue) {
         let numRows = $scope.editor.getSession().getLength()
         let currentRow = $scope.editor.getCursorPosition().row

Reply via email to