From 5f3907c7ec468139c432f342d405bf2c5a26333e 2011-12-07 07:03:37 From: Matthias BUSSONNIER Date: 2011-12-07 07:03:37 Subject: [PATCH] completer update code-miror on the fly Following @fperez advice, change the completer apparence to avoid user confusion. - Append what the user type in the completer in code-miror, (Almost) as if codemirror still have focus - distinguish between "fixed" completion part, which was sent to the kernel (now written in bold) and filtering one,handled only in JS,that the user can errase without dismissing the completer I changed the action of to dismiss the completer with what have already been typed and inserting a space instead of "picking" the currently hilighted option will still dissmiss the completer and remove everything the user as typed since the completer invocation Note that while the completer is shown, code-mirror does not show any blinking cursor --- diff --git a/IPython/frontend/html/notebook/static/css/notebook.css b/IPython/frontend/html/notebook/static/css/notebook.css index d7ea21d..52b35c9 100644 --- a/IPython/frontend/html/notebook/static/css/notebook.css +++ b/IPython/frontend/html/notebook/static/css/notebook.css @@ -419,6 +419,11 @@ div.text_cell_render { min-height:50px; } +/*fixed part of the completion*/ +.completions p b{ + font-weight:bold; +} + .completions p{ background: #DDF; /*outline: none; diff --git a/IPython/frontend/html/notebook/static/js/codecell.js b/IPython/frontend/html/notebook/static/js/codecell.js index f3f2554..e150520 100644 --- a/IPython/frontend/html/notebook/static/js/codecell.js +++ b/IPython/frontend/html/notebook/static/js/codecell.js @@ -241,19 +241,19 @@ var IPython = (function (IPython) { var key = { tab:9, esc:27, backspace:8, - space:13, + space:32, shift:16, - enter:32, + enter:13, // _ is 95 isCompSymbol : function (code) { - return (code > 64 && code <= 90) + return (code > 64 && code <= 90) || (code >= 97 && code <= 122) || (code == 95) }, dismissAndAppend : function (code) { - chararr = ['(',')','[',']','+','-','/','\\','.']; + chararr = ['(',')','[',']','+','-','/','\\','.',' ']; codearr = chararr.map(function(x){return x.charCodeAt(0)}); return jQuery.inArray(code, codearr) != -1; } @@ -330,17 +330,23 @@ var IPython = (function (IPython) { that.completion_cursor = null; }; - // insert the given text and exit the completer - var insert = function (selected_text, event) { + // update codemirror with the typed text + prev = matched_text + var update = function (inserted_text, event) { that.code_mirror.replaceRange( - selected_text, + inserted_text, {line: cur.line, ch: (cur.ch-matched_text.length)}, - {line: cur.line, ch: cur.ch} + {line: cur.line, ch: (cur.ch+prev.length-matched_text.length)} ); + prev = inserted_text if(event != null){ event.stopPropagation(); event.preventDefault(); } + }; + // insert the given text and exit the completer + var insert = function (selected_text, event) { + update(selected_text) close(); setTimeout(function(){that.code_mirror.focus();}, 50); }; @@ -373,8 +379,9 @@ var IPython = (function (IPython) { } } //clear the previous completion if any + update(typed_text,event); complete.children().children().remove(); - $('#asyoutype').text(typed_text); + $('#asyoutype').html(""+matched_text+""+typed_text.substr(matched_text.length)); select = $('#asyoutypeselect'); for (var i = 0; i').html(matches[i])); @@ -385,7 +392,7 @@ var IPython = (function (IPython) { // create html for completer var complete = $('
').addClass('completions'); complete.attr('id','complete'); - complete.append($('

').attr('id', 'asyoutype').html(matched_text));//pseudo input field + complete.append($('

').attr('id', 'asyoutype').html('fixed partuser part'));//pseudo input field var select = $('