Add Ctrl-L as a way to toggle line-numbers for any individual code cell

This commit is contained in:
Fernando Perez 2011-10-13 23:55:14 -07:00
parent 7041224f96
commit e00e604144
2 changed files with 20 additions and 9 deletions

View File

@ -48,9 +48,10 @@ var IPython = (function (IPython) {
CodeCell.prototype.handle_codemirror_keyevent = function (editor, event) {
// This method gets called in CodeMirror's onKeyDown/onKeyPress handlers and
// is used to provide custom key handling. Its return value is used to determine
// if CodeMirror should ignore the event: true = ignore, false = don't ignore.
// This method gets called in CodeMirror's onKeyDown/onKeyPress
// handlers and is used to provide custom key handling. Its return
// value is used to determine if CodeMirror should ignore the event:
// true = ignore, false = don't ignore.
if (event.keyCode === 13 && (event.shiftKey || event.ctrlKey)) {
// Always ignore shift-enter in CodeMirror as we handle it.
return true;
@ -59,8 +60,8 @@ var IPython = (function (IPython) {
var cur = editor.getCursor();
var pre_cursor = editor.getRange({line:cur.line,ch:0},cur).trim();
if (pre_cursor === "") {
// Don't autocomplete if the part of the line before the cursor is empty.
// In this case, let CodeMirror handle indentation.
// Don't autocomplete if the part of the line before the cursor
// is empty. In this case, let CodeMirror handle indentation.
return false;
} else {
// Autocomplete the current line.
@ -86,9 +87,19 @@ var IPython = (function (IPython) {
} else {
return false;
};
} else {
// keypress/keyup also trigger on TAB press, and we don't want to use those
// to disable tab completion.
} 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()
}
else {
// keypress/keyup also trigger on TAB press, and we don't want to
// use those to disable tab completion.
if (this.is_completing && event.keyCode !== 9) {
var ed_cur = editor.getCursor();
var cc_cur = this.completion_cursor;
@ -470,4 +481,3 @@ var IPython = (function (IPython) {
return IPython;
}(IPython));

View File

@ -186,6 +186,7 @@ var IPython = (function (IPython) {
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-m d', help: 'delete cell'},
{key: 'Ctrl-m a', help: 'insert cell above'},
{key: 'Ctrl-m b', help: 'insert cell below'},