Skip to content
This repository

shift tab for tooltip #2728

Merged
merged 1 commit into from over 1 year ago

1 participant

Matthias Bussonnier
Matthias Bussonnier
Collaborator

As discussed on list, use shift tab to trigger tooltip

This does not change the curent behavior, only add the shift+tab shortcut.

Note that the shift tab shortcut has a slightly different behavior. You can select part of a line and pressing shift-tab will show you the tooltip only for the selection.

This is disabled for multiline selection to still allow to unindent block of code, Keep in mind that the real real shortcut for indent unindent is Ctrl+] or [ . Select/tab is not really supported by codemirror.

Finally the "tooltip_on_tab" behavior is globally configurable via IPython.config so that it could be easily switched to false.

I can be overridden via js console for test purpose.

IPython.config.tooltip_on_tab = true | false

Take effect immediately, only on current notebook.

or via custom.js

var user_conf = {tooltip_on_tab:false | true};
$.extend(IPython.config, user_conf)
Matthias Bussonnier Carreau merged commit 99339d1 into from January 05, 2013
Matthias Bussonnier Carreau closed this January 05, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Dec 29, 2012
Matthias Bussonnier shift tqb for tooltip 77fe6f1
This page is out of date. Refresh to see the latest.
15  IPython/frontend/html/notebook/static/js/codecell.js
@@ -37,7 +37,6 @@ var IPython = (function (IPython) {
37 37
         this.kernel = kernel || null;
38 38
         this.code_mirror = null;
39 39
         this.input_prompt_number = null;
40  
-        this.tooltip_on_tab = true;
41 40
         this.collapsed = false;
42 41
         this.default_mode = 'python';
43 42
         IPython.Cell.apply(this, arguments);
@@ -48,7 +47,6 @@ var IPython = (function (IPython) {
48 47
         );
49 48
     };
50 49
 
51  
-
52 50
     CodeCell.prototype = new IPython.Cell();
53 51
 
54 52
     /**
@@ -142,6 +140,17 @@ var IPython = (function (IPython) {
142 140
             } else {
143 141
                 return true;
144 142
             };
  143
+        } else if (event.keyCode === key.TAB && event.type == 'keydown' && event.shiftKey) {
  144
+                if (editor.somethingSelected()){
  145
+                    var anchor = editor.getCursor("anchor");
  146
+                    var head = editor.getCursor("head");
  147
+                    if( anchor.line != head.line){
  148
+                        return false;
  149
+                    }
  150
+                }
  151
+                IPython.tooltip.request(that);
  152
+                event.stop();
  153
+                return true;
145 154
         } else if (event.keyCode === key.TAB && event.type == 'keydown') {
146 155
             // Tab completion.
147 156
             //Do not trim here because of tooltip
@@ -151,7 +160,7 @@ var IPython = (function (IPython) {
151 160
                 // Don't autocomplete if the part of the line before the cursor
152 161
                 // is empty.  In this case, let CodeMirror handle indentation.
153 162
                 return false;
154  
-            } else if ((pre_cursor.substr(-1) === "("|| pre_cursor.substr(-1) === " ") && that.tooltip_on_tab ) {
  163
+            } else if ((pre_cursor.substr(-1) === "("|| pre_cursor.substr(-1) === " ") && IPython.config.tooltip_on_tab ) {
155 164
                 IPython.tooltip.request(that);
156 165
                 // Prevent the event from bubbling up.
157 166
                 event.stop();
10  IPython/frontend/html/notebook/static/js/config.js
@@ -22,7 +22,7 @@ var IPython = (function (IPython) {
22 22
          * @static
23 23
          *
24 24
          **/
25  
-    var config = {
  25
+    var default_config = {
26 26
         /**
27 27
          * Dictionary of object to autodetect highlight mode for code cell.
28 28
          * Item of the dictionnary should take the form :
@@ -63,10 +63,14 @@ var IPython = (function (IPython) {
63 63
          */
64 64
         raw_cell_highlight : {
65 65
              'diff'         :{'reg':[/^diff/]}
66  
-            }
  66
+            },
  67
+
  68
+        tooltip_on_tab : true,
67 69
         };
68 70
 
69  
-    IPython.config = config;
  71
+    // use the same method to merge user configuration
  72
+    IPython.config = {};
  73
+    $.extend(IPython.config, default_config);
70 74
 
71 75
     return IPython;
72 76
 
14  IPython/frontend/html/notebook/static/js/tooltip.js
@@ -228,6 +228,10 @@ var IPython = (function (IPython) {
228 228
             ch: 0
229 229
         }, cursor).trim();
230 230
 
  231
+        if(editor.somethingSelected()){
  232
+            text = editor.getSelection();
  233
+        }
  234
+
231 235
         // need a permanent handel to code_mirror for future auto recall
232 236
         this.code_mirror = editor;
233 237
 
@@ -288,7 +292,15 @@ var IPython = (function (IPython) {
288 292
         var w = $(this.code_mirror.getScrollerElement()).width();
289 293
         // ofset of the editor
290 294
         var o = $(this.code_mirror.getScrollerElement()).offset();
291  
-        var pos = this.code_mirror.cursorCoords();
  295
+
  296
+        // whatever anchor/head order but arrow at mid x selection
  297
+        var anchor = this.code_mirror.cursorCoords(false);
  298
+        var head  = this.code_mirror.cursorCoords(true);
  299
+        var pos = {};
  300
+        pos.y = head.y
  301
+        pos.yBot = head.yBot
  302
+        pos.x = (head.x+anchor.x)/2;
  303
+
292 304
         var xinit = pos.x;
293 305
         var xinter = o.left + (xinit - o.left) / w * (w - 450);
294 306
         var posarrowleft = xinit - xinter;
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.