From b12c6754e8f0d270c3cd301b86ae66360bd2c060 2011-10-17 03:02:53 From: Fernando Perez Date: 2011-10-17 03:02:53 Subject: [PATCH] Refactor line num. toggle into proper function, access via C-m-l. This makes the keybinding consistent with the rest, updated help dialog. --- diff --git a/IPython/frontend/html/notebook/static/js/codecell.js b/IPython/frontend/html/notebook/static/js/codecell.js index e7506c9..279bad6 100644 --- a/IPython/frontend/html/notebook/static/js/codecell.js +++ b/IPython/frontend/html/notebook/static/js/codecell.js @@ -90,12 +90,7 @@ var IPython = (function (IPython) { } else if (event.keyCode === 76 && event.ctrlKey && event.shiftKey && event.type == 'keydown') { // toggle line numbers with Ctrl-Shift-L - if (this.code_mirror.getOption('lineNumbers') == false) { - this.code_mirror.setOption('lineNumbers', true); - } else { - this.code_mirror.setOption('lineNumbers', false); - } - this.code_mirror.refresh() + this.toggle_line_numbers() } else { // keypress/keyup also trigger on TAB press, and we don't want to @@ -188,6 +183,14 @@ var IPython = (function (IPython) { select.focus(); }; + CodeCell.prototype.toggle_line_numbers = function () { + if (this.code_mirror.getOption('lineNumbers') == false) { + this.code_mirror.setOption('lineNumbers', true); + } else { + this.code_mirror.setOption('lineNumbers', false); + } + this.code_mirror.refresh() + }; CodeCell.prototype.select = function () { IPython.Cell.prototype.select.apply(this); diff --git a/IPython/frontend/html/notebook/static/js/notebook.js b/IPython/frontend/html/notebook/static/js/notebook.js index e98c41f..b67aa1a 100644 --- a/IPython/frontend/html/notebook/static/js/notebook.js +++ b/IPython/frontend/html/notebook/static/js/notebook.js @@ -140,6 +140,11 @@ var IPython = (function (IPython) { IPython.notebook.kernel.interrupt(); that.control_key_active = false; return false; + } else if (event.which === 76 && that.control_key_active) { + // Toggle line numbers = l + that.cell_toggle_line_numbers(); + that.control_key_active = false; + return false; } else if (event.which === 190 && that.control_key_active) { // Restart kernel = . # matches qt console IPython.notebook.restart_kernel(); @@ -195,12 +200,12 @@ var IPython = (function (IPython) { var dialog = $('
'); var shortcuts = [ {key: 'Shift-Enter', help: 'run cell'}, - {key: 'Ctrl-Enter', help: 'run cell in terminal mode'}, - {key: 'Ctrl-Shift-L', help: 'toggle line numbering'}, + {key: 'Ctrl-Enter', help: 'run cell in-place'}, {key: 'Ctrl-m d', help: 'delete cell'}, {key: 'Ctrl-m a', help: 'insert cell above'}, {key: 'Ctrl-m b', help: 'insert cell below'}, {key: 'Ctrl-m t', help: 'toggle output'}, + {key: 'Ctrl-m l', help: 'toggle line numbers'}, {key: 'Ctrl-m s', help: 'save notebook'}, {key: 'Ctrl-m j', help: 'move cell down'}, {key: 'Ctrl-m k', help: 'move cell up'}, @@ -210,7 +215,7 @@ var IPython = (function (IPython) { {key: 'Ctrl-m n', help: 'select next'}, {key: 'Ctrl-m i', help: 'interrupt kernel'}, {key: 'Ctrl-m .', help: 'restart kernel'}, - {key: 'Ctrl-m h', help: 'display keyboard shortcuts'} + {key: 'Ctrl-m h', help: 'show keyboard shortcuts'} ]; for (var i=0; i'). @@ -615,6 +620,11 @@ var IPython = (function (IPython) { this.dirty = true; }; + // Other cell functions: line numbers, ... + + Notebook.prototype.cell_toggle_line_numbers = function() { + this.selected_cell().toggle_line_numbers() + }; // Kernel related things diff --git a/IPython/frontend/html/notebook/templates/notebook.html b/IPython/frontend/html/notebook/templates/notebook.html index a9a84e2..087b300 100644 --- a/IPython/frontend/html/notebook/templates/notebook.html +++ b/IPython/frontend/html/notebook/templates/notebook.html @@ -176,7 +176,7 @@
- + Actions @@ -217,7 +217,7 @@ Shift-Enter :
- run in terminal mode + run selected cell in-place Ctrl-Enter :