##// END OF EJS Templates
Fixing tab completion edge cases.
Brian E. Granger -
Show More
@@ -47,7 +47,8 b' var IPython = (function (IPython) {'
47 if (event.keyCode === 13 && event.shiftKey) {
47 if (event.keyCode === 13 && event.shiftKey) {
48 // Always ignore shift-enter in CodeMirror as we handle it.
48 // Always ignore shift-enter in CodeMirror as we handle it.
49 return true;
49 return true;
50 } else if (event.keyCode === 9) {
50 } else if (event.keyCode === 9 && event.type == 'keydown') {
51 // Tab completion.
51 var cur = editor.getCursor();
52 var cur = editor.getCursor();
52 var pre_cursor = editor.getRange({line:cur.line,ch:0},cur).trim();
53 var pre_cursor = editor.getRange({line:cur.line,ch:0},cur).trim();
53 if (pre_cursor === "") {
54 if (pre_cursor === "") {
@@ -79,18 +80,24 b' var IPython = (function (IPython) {'
79 return false;
80 return false;
80 };
81 };
81 } else {
82 } else {
82 if (this.is_completing && this.completion_cursor !== editor.getCursor()) {
83 // keypress/keyup also trigger on TAB press, and we don't want to use those
83 this.is_completing = false;
84 // to disable tab completion.
84 this.completion_cursor = null;
85 if (this.is_completing && event.keyCode !== 9) {
85 }
86 var ed_cur = editor.getCursor();
87 var cc_cur = this.completion_cursor;
88 if (ed_cur.line !== cc_cur.line || ed_cur.ch !== cc_cur.ch) {
89 this.is_completing = false;
90 this.completion_cursor = null;
91 };
92 };
86 return false;
93 return false;
87 };
94 };
88 };
95 };
89
96
90
97
91 CodeCell.prototype.finish_completing = function (matched_text, matches) {
98 CodeCell.prototype.finish_completing = function (matched_text, matches) {
92 if (!this.is_completing || matches.length === 0) {return;}
93 // console.log("Got matches", matched_text, matches);
99 // console.log("Got matches", matched_text, matches);
100 if (!this.is_completing || matches.length === 0) {return;}
94
101
95 var that = this;
102 var that = this;
96 var cur = this.completion_cursor;
103 var cur = this.completion_cursor;
@@ -151,7 +158,7 b' var IPython = (function (IPython) {'
151 // but we want the default action.
158 // but we want the default action.
152 event.stopPropagation();
159 event.stopPropagation();
153 } else {
160 } else {
154 // All other key presses simple exit completion.
161 // All other key presses exit completion.
155 event.stopPropagation();
162 event.stopPropagation();
156 event.preventDefault();
163 event.preventDefault();
157 close();
164 close();
General Comments 0
You need to be logged in to leave comments. Login now