Refactor line num. toggle into proper function, access via C-m-l.

This makes the keybinding consistent with the rest, updated help dialog.
This commit is contained in:
Fernando Perez 2011-10-16 15:19:28 -07:00
parent 8fb9f71e42
commit e41ba5a75c
3 changed files with 24 additions and 11 deletions

View File

@ -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);

View File

@ -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 = $('<div/>');
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<shortcuts.length; i++) {
dialog.append($('<div>').
@ -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

View File

@ -176,7 +176,7 @@
<div class="section_content">
<div class="section_row">
<span id="int_restart" class="section_row_buttons">
<button id="int_kernel">Interrupt</button>
<button id="int_kernel"><u>I</u>nterrupt</button>
<button id="restart_kernel">Restart</button>
</span>
<span class="section_row_header">Actions</span>
@ -217,7 +217,7 @@
<span class="help_string_label">Shift-Enter :</span>
</div>
<div class="section_row">
<span class="help_string">run in terminal mode</span>
<span class="help_string">run selected cell in-place</span>
<span class="help_string_label">Ctrl-Enter :</span>
</div>
<div class="section_row">