From 9e9f80aaedb5170890110869fbf0023455335bd3 2015-01-13 22:06:43 From: Mathieu Date: 2015-01-13 22:06:43 Subject: [PATCH] fix kernel change breaking new notebook list --- diff --git a/IPython/html/static/notebook/js/kernelselector.js b/IPython/html/static/notebook/js/kernelselector.js index d82200e..ef2a439 100644 --- a/IPython/html/static/notebook/js/kernelselector.js +++ b/IPython/html/static/notebook/js/kernelselector.js @@ -86,9 +86,28 @@ define([ // put the current kernel at the top of File > New Notebook var cur_kernel_entry = $("#new-notebook-submenu-" + ks.name); - if (cur_kernel_entry.length) { - cur_kernel_entry.parent().prepend($("
  • ").attr("class","divider")) - .prepend(cur_kernel_entry); + var parent = cur_kernel_entry.parent(); + // do something only if there is more than one kernel + if (parent.children().length > 1) { + // first, sort back the submenu + parent.append( + parent.children("li[class!='divider']").sort( + function (a,b) { + var da = $("a",a).text(); + var db = $("a",b).text(); + if (da === db) { + return 0; + } else if (da > db) { + return 1; + } else { + return -1; + }})); + // then, if there is no divider yet, add one + if (!parent.children("li[class='divider']").length) { + parent.prepend($("
  • ").attr("class","divider")); + } + // finally, put the current kernel at the top + parent.prepend(cur_kernel_entry); } // load logo