mirror of
https://github.com/jupyter/notebook.git
synced 2025-04-18 14:10:26 +08:00
Added scroll mode selector,
fixed rebase conflicts.
This commit is contained in:
parent
62a21b0e6f
commit
7e7683a587
@ -1,7 +1,12 @@
|
||||
// Copyright (c) IPython Development Team.
|
||||
// Distributed under the terms of the Modified BSD License.
|
||||
|
||||
var IPython = (function (IPython) {
|
||||
define([
|
||||
'base/js/namespace',
|
||||
'jquery',
|
||||
'base/js/utils',
|
||||
'base/js/keyboard',
|
||||
], function(IPython, $, utils, keyboard) {
|
||||
"use strict";
|
||||
|
||||
var browser = utils.browser[0];
|
||||
@ -98,386 +103,386 @@ var IPython = (function (IPython) {
|
||||
KeyboardManager.prototype.get_default_edit_shortcuts = function() {
|
||||
var that = this;
|
||||
return {
|
||||
'esc' : {
|
||||
help : 'command mode',
|
||||
help_index : 'aa',
|
||||
handler : function (event) {
|
||||
that.notebook.command_mode();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'ctrl-m' : {
|
||||
help : 'command mode',
|
||||
help_index : 'ab',
|
||||
handler : function (event) {
|
||||
that.notebook.command_mode();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'up' : {
|
||||
help : '',
|
||||
help_index : '',
|
||||
handler : function (event) {
|
||||
var index = that.notebook.get_selected_index();
|
||||
var cell = that.notebook.get_cell(index);
|
||||
if (cell && cell.at_top() && index !== 0) {
|
||||
event.preventDefault();
|
||||
'esc' : {
|
||||
help : 'command mode',
|
||||
help_index : 'aa',
|
||||
handler : function (event) {
|
||||
that.notebook.command_mode();
|
||||
that.notebook.select_prev();
|
||||
that.notebook.edit_mode();
|
||||
var cm = that.notebook.get_selected_cell().code_mirror;
|
||||
cm.setCursor(cm.lastLine(), 0);
|
||||
return false;
|
||||
} else if (cell) {
|
||||
var cm = cell.code_mirror;
|
||||
cm.execCommand('goLineUp');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
},
|
||||
'down' : {
|
||||
help : '',
|
||||
help_index : '',
|
||||
handler : function (event) {
|
||||
var index = that.notebook.get_selected_index();
|
||||
var cell = that.notebook.get_cell(index);
|
||||
if (cell.at_bottom() && index !== (that.notebook.ncells()-1)) {
|
||||
event.preventDefault();
|
||||
},
|
||||
'ctrl-m' : {
|
||||
help : 'command mode',
|
||||
help_index : 'ab',
|
||||
handler : function (event) {
|
||||
that.notebook.command_mode();
|
||||
that.notebook.select_next();
|
||||
that.notebook.edit_mode();
|
||||
var cm = that.notebook.get_selected_cell().code_mirror;
|
||||
cm.setCursor(0, 0);
|
||||
return false;
|
||||
} else {
|
||||
var cm = cell.code_mirror;
|
||||
cm.execCommand('goLineDown');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
},
|
||||
'ctrl-shift--' : {
|
||||
help : 'split cell',
|
||||
help_index : 'ea',
|
||||
handler : function (event) {
|
||||
that.notebook.split_cell();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'ctrl-shift-subtract' : {
|
||||
help : '',
|
||||
help_index : 'eb',
|
||||
handler : function (event) {
|
||||
that.notebook.split_cell();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
'up' : {
|
||||
help : '',
|
||||
help_index : '',
|
||||
handler : function (event) {
|
||||
var index = that.notebook.get_selected_index();
|
||||
var cell = that.notebook.get_cell(index);
|
||||
if (cell && cell.at_top() && index !== 0) {
|
||||
event.preventDefault();
|
||||
that.notebook.command_mode();
|
||||
that.notebook.select_prev();
|
||||
that.notebook.edit_mode();
|
||||
var cm = that.notebook.get_selected_cell().code_mirror;
|
||||
cm.setCursor(cm.lastLine(), 0);
|
||||
return false;
|
||||
} else if (cell) {
|
||||
var cm = cell.code_mirror;
|
||||
cm.execCommand('goLineUp');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
},
|
||||
'down' : {
|
||||
help : '',
|
||||
help_index : '',
|
||||
handler : function (event) {
|
||||
var index = that.notebook.get_selected_index();
|
||||
var cell = that.notebook.get_cell(index);
|
||||
if (cell.at_bottom() && index !== (that.notebook.ncells()-1)) {
|
||||
event.preventDefault();
|
||||
that.notebook.command_mode();
|
||||
that.notebook.select_next();
|
||||
that.notebook.edit_mode();
|
||||
var cm = that.notebook.get_selected_cell().code_mirror;
|
||||
cm.setCursor(0, 0);
|
||||
return false;
|
||||
} else {
|
||||
var cm = cell.code_mirror;
|
||||
cm.execCommand('goLineDown');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
},
|
||||
'ctrl-shift--' : {
|
||||
help : 'split cell',
|
||||
help_index : 'ea',
|
||||
handler : function (event) {
|
||||
that.notebook.split_cell();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'ctrl-shift-subtract' : {
|
||||
help : '',
|
||||
help_index : 'eb',
|
||||
handler : function (event) {
|
||||
that.notebook.split_cell();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
KeyboardManager.prototype.get_default_command_shortcuts = function() {
|
||||
var that = this;
|
||||
return {
|
||||
'space': {
|
||||
help: "Scroll down to next H1 cell",
|
||||
handler: function(event) {
|
||||
return that.notebook.scrollmanager.scroll(1);
|
||||
'space': {
|
||||
help: "Scroll down to next H1 cell",
|
||||
handler: function(event) {
|
||||
return that.notebook.scrollmanager.scroll(1);
|
||||
},
|
||||
},
|
||||
},
|
||||
'shift-space': {
|
||||
help: "Scroll up to previous H1 cell",
|
||||
handler: function(event) {
|
||||
return that.notebook.scrollmanager.scroll(-1);
|
||||
'shift-space': {
|
||||
help: "Scroll up to previous H1 cell",
|
||||
handler: function(event) {
|
||||
return that.notebook.scrollmanager.scroll(-1);
|
||||
},
|
||||
},
|
||||
},
|
||||
'enter' : {
|
||||
help : 'edit mode',
|
||||
help_index : 'aa',
|
||||
handler : function (event) {
|
||||
that.notebook.edit_mode();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'up' : {
|
||||
help : 'select previous cell',
|
||||
help_index : 'da',
|
||||
handler : function (event) {
|
||||
var index = that.notebook.get_selected_index();
|
||||
if (index !== 0 && index !== null) {
|
||||
'enter' : {
|
||||
help : 'edit mode',
|
||||
help_index : 'aa',
|
||||
handler : function (event) {
|
||||
that.notebook.edit_mode();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'up' : {
|
||||
help : 'select previous cell',
|
||||
help_index : 'da',
|
||||
handler : function (event) {
|
||||
var index = that.notebook.get_selected_index();
|
||||
if (index !== 0 && index !== null) {
|
||||
that.notebook.select_prev();
|
||||
that.notebook.focus_cell();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'down' : {
|
||||
help : 'select next cell',
|
||||
help_index : 'db',
|
||||
handler : function (event) {
|
||||
var index = that.notebook.get_selected_index();
|
||||
if (index !== (that.notebook.ncells()-1) && index !== null) {
|
||||
that.notebook.select_next();
|
||||
that.notebook.focus_cell();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'k' : {
|
||||
help : 'select previous cell',
|
||||
help_index : 'dc',
|
||||
handler : function (event) {
|
||||
var index = that.notebook.get_selected_index();
|
||||
if (index !== 0 && index !== null) {
|
||||
that.notebook.select_prev();
|
||||
that.notebook.focus_cell();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'j' : {
|
||||
help : 'select next cell',
|
||||
help_index : 'dd',
|
||||
handler : function (event) {
|
||||
var index = that.notebook.get_selected_index();
|
||||
if (index !== (that.notebook.ncells()-1) && index !== null) {
|
||||
that.notebook.select_next();
|
||||
that.notebook.focus_cell();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'x' : {
|
||||
help : 'cut cell',
|
||||
help_index : 'ee',
|
||||
handler : function (event) {
|
||||
that.notebook.cut_cell();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'c' : {
|
||||
help : 'copy cell',
|
||||
help_index : 'ef',
|
||||
handler : function (event) {
|
||||
that.notebook.copy_cell();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'shift-v' : {
|
||||
help : 'paste cell above',
|
||||
help_index : 'eg',
|
||||
handler : function (event) {
|
||||
that.notebook.paste_cell_above();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'v' : {
|
||||
help : 'paste cell below',
|
||||
help_index : 'eh',
|
||||
handler : function (event) {
|
||||
that.notebook.paste_cell_below();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'd' : {
|
||||
help : 'delete cell (press twice)',
|
||||
help_index : 'ej',
|
||||
count: 2,
|
||||
handler : function (event) {
|
||||
that.notebook.delete_cell();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'a' : {
|
||||
help : 'insert cell above',
|
||||
help_index : 'ec',
|
||||
handler : function (event) {
|
||||
that.notebook.insert_cell_above();
|
||||
that.notebook.select_prev();
|
||||
that.notebook.focus_cell();
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'down' : {
|
||||
help : 'select next cell',
|
||||
help_index : 'db',
|
||||
handler : function (event) {
|
||||
var index = that.notebook.get_selected_index();
|
||||
if (index !== (that.notebook.ncells()-1) && index !== null) {
|
||||
},
|
||||
'b' : {
|
||||
help : 'insert cell below',
|
||||
help_index : 'ed',
|
||||
handler : function (event) {
|
||||
that.notebook.insert_cell_below();
|
||||
that.notebook.select_next();
|
||||
that.notebook.focus_cell();
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'k' : {
|
||||
help : 'select previous cell',
|
||||
help_index : 'dc',
|
||||
handler : function (event) {
|
||||
var index = that.notebook.get_selected_index();
|
||||
if (index !== 0 && index !== null) {
|
||||
that.notebook.select_prev();
|
||||
that.notebook.focus_cell();
|
||||
},
|
||||
'y' : {
|
||||
help : 'to code',
|
||||
help_index : 'ca',
|
||||
handler : function (event) {
|
||||
that.notebook.to_code();
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'j' : {
|
||||
help : 'select next cell',
|
||||
help_index : 'dd',
|
||||
handler : function (event) {
|
||||
var index = that.notebook.get_selected_index();
|
||||
if (index !== (that.notebook.ncells()-1) && index !== null) {
|
||||
that.notebook.select_next();
|
||||
that.notebook.focus_cell();
|
||||
},
|
||||
'm' : {
|
||||
help : 'to markdown',
|
||||
help_index : 'cb',
|
||||
handler : function (event) {
|
||||
that.notebook.to_markdown();
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'x' : {
|
||||
help : 'cut cell',
|
||||
help_index : 'ee',
|
||||
handler : function (event) {
|
||||
that.notebook.cut_cell();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'c' : {
|
||||
help : 'copy cell',
|
||||
help_index : 'ef',
|
||||
handler : function (event) {
|
||||
that.notebook.copy_cell();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'shift-v' : {
|
||||
help : 'paste cell above',
|
||||
help_index : 'eg',
|
||||
handler : function (event) {
|
||||
that.notebook.paste_cell_above();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'v' : {
|
||||
help : 'paste cell below',
|
||||
help_index : 'eh',
|
||||
handler : function (event) {
|
||||
that.notebook.paste_cell_below();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'd' : {
|
||||
help : 'delete cell (press twice)',
|
||||
help_index : 'ej',
|
||||
count: 2,
|
||||
handler : function (event) {
|
||||
that.notebook.delete_cell();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'a' : {
|
||||
help : 'insert cell above',
|
||||
help_index : 'ec',
|
||||
handler : function (event) {
|
||||
that.notebook.insert_cell_above();
|
||||
that.notebook.select_prev();
|
||||
that.notebook.focus_cell();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'b' : {
|
||||
help : 'insert cell below',
|
||||
help_index : 'ed',
|
||||
handler : function (event) {
|
||||
that.notebook.insert_cell_below();
|
||||
that.notebook.select_next();
|
||||
that.notebook.focus_cell();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'y' : {
|
||||
help : 'to code',
|
||||
help_index : 'ca',
|
||||
handler : function (event) {
|
||||
that.notebook.to_code();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'm' : {
|
||||
help : 'to markdown',
|
||||
help_index : 'cb',
|
||||
handler : function (event) {
|
||||
that.notebook.to_markdown();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'r' : {
|
||||
help : 'to raw',
|
||||
help_index : 'cc',
|
||||
handler : function (event) {
|
||||
that.notebook.to_raw();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'1' : {
|
||||
help : 'to heading 1',
|
||||
help_index : 'cd',
|
||||
handler : function (event) {
|
||||
that.notebook.to_heading(undefined, 1);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'2' : {
|
||||
help : 'to heading 2',
|
||||
help_index : 'ce',
|
||||
handler : function (event) {
|
||||
that.notebook.to_heading(undefined, 2);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'3' : {
|
||||
help : 'to heading 3',
|
||||
help_index : 'cf',
|
||||
handler : function (event) {
|
||||
that.notebook.to_heading(undefined, 3);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'4' : {
|
||||
help : 'to heading 4',
|
||||
help_index : 'cg',
|
||||
handler : function (event) {
|
||||
that.notebook.to_heading(undefined, 4);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'5' : {
|
||||
help : 'to heading 5',
|
||||
help_index : 'ch',
|
||||
handler : function (event) {
|
||||
that.notebook.to_heading(undefined, 5);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'6' : {
|
||||
help : 'to heading 6',
|
||||
help_index : 'ci',
|
||||
handler : function (event) {
|
||||
that.notebook.to_heading(undefined, 6);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'o' : {
|
||||
help : 'toggle output',
|
||||
help_index : 'gb',
|
||||
handler : function (event) {
|
||||
that.notebook.toggle_output();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'shift-o' : {
|
||||
help : 'toggle output scrolling',
|
||||
help_index : 'gc',
|
||||
handler : function (event) {
|
||||
that.notebook.toggle_output_scroll();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
's' : {
|
||||
help : 'save notebook',
|
||||
help_index : 'fa',
|
||||
handler : function (event) {
|
||||
that.notebook.save_checkpoint();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'ctrl-j' : {
|
||||
help : 'move cell down',
|
||||
help_index : 'eb',
|
||||
handler : function (event) {
|
||||
that.notebook.move_cell_down();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'ctrl-k' : {
|
||||
help : 'move cell up',
|
||||
help_index : 'ea',
|
||||
handler : function (event) {
|
||||
that.notebook.move_cell_up();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'l' : {
|
||||
help : 'toggle line numbers',
|
||||
help_index : 'ga',
|
||||
handler : function (event) {
|
||||
that.notebook.cell_toggle_line_numbers();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'i' : {
|
||||
help : 'interrupt kernel (press twice)',
|
||||
help_index : 'ha',
|
||||
count: 2,
|
||||
handler : function (event) {
|
||||
that.notebook.kernel.interrupt();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'0' : {
|
||||
help : 'restart kernel (press twice)',
|
||||
help_index : 'hb',
|
||||
count: 2,
|
||||
handler : function (event) {
|
||||
that.notebook.restart_kernel();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'h' : {
|
||||
help : 'keyboard shortcuts',
|
||||
help_index : 'ge',
|
||||
handler : function (event) {
|
||||
that.quick_help.show_keyboard_shortcuts();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'z' : {
|
||||
help : 'undo last delete',
|
||||
help_index : 'ei',
|
||||
handler : function (event) {
|
||||
that.notebook.undelete_cell();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'shift-m' : {
|
||||
help : 'merge cell below',
|
||||
help_index : 'ek',
|
||||
handler : function (event) {
|
||||
that.notebook.merge_cell_below();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'q' : {
|
||||
help : 'close pager',
|
||||
help_index : 'gd',
|
||||
handler : function (event) {
|
||||
that.pager.collapse();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
'r' : {
|
||||
help : 'to raw',
|
||||
help_index : 'cc',
|
||||
handler : function (event) {
|
||||
that.notebook.to_raw();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'1' : {
|
||||
help : 'to heading 1',
|
||||
help_index : 'cd',
|
||||
handler : function (event) {
|
||||
that.notebook.to_heading(undefined, 1);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'2' : {
|
||||
help : 'to heading 2',
|
||||
help_index : 'ce',
|
||||
handler : function (event) {
|
||||
that.notebook.to_heading(undefined, 2);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'3' : {
|
||||
help : 'to heading 3',
|
||||
help_index : 'cf',
|
||||
handler : function (event) {
|
||||
that.notebook.to_heading(undefined, 3);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'4' : {
|
||||
help : 'to heading 4',
|
||||
help_index : 'cg',
|
||||
handler : function (event) {
|
||||
that.notebook.to_heading(undefined, 4);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'5' : {
|
||||
help : 'to heading 5',
|
||||
help_index : 'ch',
|
||||
handler : function (event) {
|
||||
that.notebook.to_heading(undefined, 5);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'6' : {
|
||||
help : 'to heading 6',
|
||||
help_index : 'ci',
|
||||
handler : function (event) {
|
||||
that.notebook.to_heading(undefined, 6);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'o' : {
|
||||
help : 'toggle output',
|
||||
help_index : 'gb',
|
||||
handler : function (event) {
|
||||
that.notebook.toggle_output();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'shift-o' : {
|
||||
help : 'toggle output scrolling',
|
||||
help_index : 'gc',
|
||||
handler : function (event) {
|
||||
that.notebook.toggle_output_scroll();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
's' : {
|
||||
help : 'save notebook',
|
||||
help_index : 'fa',
|
||||
handler : function (event) {
|
||||
that.notebook.save_checkpoint();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'ctrl-j' : {
|
||||
help : 'move cell down',
|
||||
help_index : 'eb',
|
||||
handler : function (event) {
|
||||
that.notebook.move_cell_down();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'ctrl-k' : {
|
||||
help : 'move cell up',
|
||||
help_index : 'ea',
|
||||
handler : function (event) {
|
||||
that.notebook.move_cell_up();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'l' : {
|
||||
help : 'toggle line numbers',
|
||||
help_index : 'ga',
|
||||
handler : function (event) {
|
||||
that.notebook.cell_toggle_line_numbers();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'i' : {
|
||||
help : 'interrupt kernel (press twice)',
|
||||
help_index : 'ha',
|
||||
count: 2,
|
||||
handler : function (event) {
|
||||
that.notebook.kernel.interrupt();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'0' : {
|
||||
help : 'restart kernel (press twice)',
|
||||
help_index : 'hb',
|
||||
count: 2,
|
||||
handler : function (event) {
|
||||
that.notebook.restart_kernel();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'h' : {
|
||||
help : 'keyboard shortcuts',
|
||||
help_index : 'ge',
|
||||
handler : function (event) {
|
||||
that.quick_help.show_keyboard_shortcuts();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'z' : {
|
||||
help : 'undo last delete',
|
||||
help_index : 'ei',
|
||||
handler : function (event) {
|
||||
that.notebook.undelete_cell();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'shift-m' : {
|
||||
help : 'merge cell below',
|
||||
help_index : 'ek',
|
||||
handler : function (event) {
|
||||
that.notebook.merge_cell_below();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
'q' : {
|
||||
help : 'close pager',
|
||||
help_index : 'gd',
|
||||
handler : function (event) {
|
||||
that.pager.collapse();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
KeyboardManager.prototype.bind_events = function () {
|
||||
|
@ -19,7 +19,6 @@ require([
|
||||
'notebook/js/keyboardmanager',
|
||||
'notebook/js/config',
|
||||
'notebook/js/kernelselector',
|
||||
'notebook/js/scrollmanager'
|
||||
// only loaded, not used:
|
||||
'custom/custom',
|
||||
], function(
|
||||
@ -39,8 +38,7 @@ require([
|
||||
savewidget,
|
||||
keyboardmanager,
|
||||
config,
|
||||
kernelselector,
|
||||
scrollmanager
|
||||
kernelselector
|
||||
) {
|
||||
"use strict";
|
||||
|
||||
@ -69,7 +67,6 @@ require([
|
||||
save_widget: save_widget,
|
||||
config: user_config},
|
||||
common_options));
|
||||
var scrollmanager = new scrollmanager.ScrollManager(notebook);
|
||||
var login_widget = new loginwidget.LoginWidget('span#login_widget', common_options);
|
||||
var toolbar = new maintoolbar.MainToolBar('#maintoolbar-container', {
|
||||
notebook: notebook,
|
||||
@ -135,7 +132,6 @@ require([
|
||||
IPython.save_widget = save_widget;
|
||||
IPython.config = user_config;
|
||||
IPython.tooltip = notebook.tooltip;
|
||||
IPython.scrollmanager = scrollmanager;
|
||||
|
||||
events.trigger('app_initialized.NotebookApp');
|
||||
notebook.load_notebook(common_options.notebook_name, common_options.notebook_path);
|
||||
|
@ -6,7 +6,8 @@ define([
|
||||
'jquery',
|
||||
'notebook/js/toolbar',
|
||||
'notebook/js/celltoolbar',
|
||||
], function(IPython, $, toolbar, celltoolbar) {
|
||||
'notebook/js/scrollmanager'
|
||||
], function(IPython, $, toolbar, celltoolbar, scrollmanager) {
|
||||
"use strict";
|
||||
|
||||
var MainToolBar = function (selector, options) {
|
||||
@ -24,6 +25,7 @@ define([
|
||||
this.construct();
|
||||
this.add_celltype_list();
|
||||
this.add_celltoolbar_list();
|
||||
this.add_scrollmanager_list();
|
||||
this.bind_events();
|
||||
};
|
||||
|
||||
@ -187,6 +189,11 @@ define([
|
||||
};
|
||||
|
||||
|
||||
MainToolBar.prototype.add_scrollmanager_list = function () {
|
||||
this._scrollselector = new scrollmanager.ScrollSelector(this.element, this.notebook);
|
||||
};
|
||||
|
||||
|
||||
MainToolBar.prototype.bind_events = function () {
|
||||
var that = this;
|
||||
|
||||
|
@ -18,6 +18,7 @@ define([
|
||||
'notebook/js/celltoolbarpresets/default',
|
||||
'notebook/js/celltoolbarpresets/rawcell',
|
||||
'notebook/js/celltoolbarpresets/slideshow',
|
||||
'notebook/js/scrollmanager'
|
||||
], function (
|
||||
IPython,
|
||||
$,
|
||||
@ -34,7 +35,8 @@ define([
|
||||
tooltip,
|
||||
default_celltoolbar,
|
||||
rawcell_celltoolbar,
|
||||
slideshow_celltoolbar
|
||||
slideshow_celltoolbar,
|
||||
scrollmanager
|
||||
) {
|
||||
|
||||
var Notebook = function (selector, options) {
|
||||
@ -64,6 +66,9 @@ define([
|
||||
this.ws_url = options.ws_url;
|
||||
this._session_starting = false;
|
||||
this.default_cell_type = this.config.default_cell_type || 'code';
|
||||
|
||||
// Create and register scroll managers.
|
||||
this.scrollmanager = new scrollmanager.ScrollManager(this);
|
||||
// default_kernel_name is a temporary measure while we implement proper
|
||||
// kernel selection and delayed start. Do not rely on it.
|
||||
this.default_kernel_name = 'python';
|
||||
@ -135,7 +140,7 @@ define([
|
||||
rawcell_celltoolbar.register(this);
|
||||
slideshow_celltoolbar.register(this);
|
||||
};
|
||||
|
||||
|
||||
Notebook.options_default = {
|
||||
// can be any cell type, or the special values of
|
||||
// 'above', 'below', or 'selected' to get the value from another cell.
|
||||
|
@ -1,9 +1,51 @@
|
||||
// Copyright (c) IPython Development Team.
|
||||
// Distributed under the terms of the Modified BSD License.
|
||||
define([], function(){
|
||||
define(['jquery'], function($){
|
||||
"use strict";
|
||||
|
||||
var ScrollManager = function (notebook) {
|
||||
var ScrollSelector = function(element, notebook) {
|
||||
// Public constructor.
|
||||
this.notebook = notebook;
|
||||
$('<span />')
|
||||
.addClass('nabar-text')
|
||||
.text('Scrolling Mode:')
|
||||
.appendTo(element);
|
||||
this._combo = $('<select />')
|
||||
.addClass('form-control select-xs')
|
||||
.appendTo(element);
|
||||
|
||||
// Redirect class level manager registration to this instance.
|
||||
this._registered = {};
|
||||
ScrollSelector.register = $.proxy(this.register, this);
|
||||
|
||||
// Register cached managers.
|
||||
for (var i =0; i < ScrollSelector.registered.length; i++) {
|
||||
this.register.apply(this, ScrollSelector.registered[i]);
|
||||
}
|
||||
|
||||
// Listen for scroll manager change, apply it to the notebook.
|
||||
var that = this;
|
||||
this._combo.change(function(){
|
||||
var manager = that._registered[$(this).find("option:selected").val()];
|
||||
that.notebook.ScrollSelector = manager;
|
||||
});
|
||||
};
|
||||
|
||||
// Cache scroll managers registered before the construction of a scroll
|
||||
// manager.
|
||||
ScrollSelector.registered = [];
|
||||
ScrollSelector.register = function(name, manager) {
|
||||
ScrollSelector.registered.push(arguments);
|
||||
};
|
||||
ScrollSelector.prototype.register = function(name, manager) {
|
||||
this._registered[name] = manager;
|
||||
this._combo.append($('<option />')
|
||||
.val(name)
|
||||
.text(name));
|
||||
};
|
||||
|
||||
|
||||
var ScrollManager = function(notebook) {
|
||||
// Public constructor.
|
||||
this.notebook = notebook;
|
||||
this.animation_speed = 250; //ms
|
||||
@ -16,6 +58,62 @@ define([], function(){
|
||||
// ----------
|
||||
// delta: integer
|
||||
// direction to scroll the document. Positive is downwards.
|
||||
this.scroll_some(delta);
|
||||
return false;
|
||||
};
|
||||
|
||||
ScrollManager.prototype.scroll_to = function(destination) {
|
||||
// Scroll to an element in the notebook.
|
||||
$('#notebook').animate({'scrollTop': $(destination).offset().top + $('#notebook').scrollTop() - $('#notebook').offset().top}, this.animation_speed);
|
||||
};
|
||||
|
||||
ScrollManager.prototype.scroll_some = function(pages) {
|
||||
// Scroll up or down a given number of pages.
|
||||
$('#notebook').animate({'scrollTop': $('#notebook').scrollTop() + pages * $('#notebook').height()}, this.animation_speed);
|
||||
};
|
||||
|
||||
ScrollManager.prototype.get_first_visible_cell = function() {
|
||||
// Gets the index of the first visible cell in the document.
|
||||
|
||||
// First, attempt to be smart by guessing the index of the cell we are
|
||||
// scrolled to. Then, walk from there up or down until the right cell
|
||||
// is found. To guess the index, get the top of the last cell, and
|
||||
// divide that by the number of cells to get an average cell height.
|
||||
// Then divide the scroll height by the average cell height.
|
||||
var cell_count = that.notebook.ncells();
|
||||
var first_cell_top = that.notebook.get_cell(0).element.offset.top();
|
||||
var last_cell_top = that.notebook.get_cell(cell_count-1).element.offset.top();
|
||||
var avg_cell_height = (last_cell_top - first_cell_top) / cell_count;
|
||||
var $notebook = $('#notebook').scrollTop();
|
||||
var i = Math.ceil($notebook.scrollTop() / avg_cell_height);
|
||||
i = min(max(i , 0), cell_count - 1);
|
||||
|
||||
while (that.notebook.get_cell(i).element.offset.top() - first_cell_top < $notebook.scrollTop() && i < cell_count - 1) {
|
||||
i += 1;
|
||||
}
|
||||
|
||||
while (that.notebook.get_cell(i).element.offset.top() - first_cell_top > $notebook.scrollTop() && i >= 0) {
|
||||
i -= 1;
|
||||
}
|
||||
return min(i + 1, cell_count - 1);
|
||||
};
|
||||
|
||||
|
||||
var HeadingScrollManager = function(notebook, heading_level) {
|
||||
// Public constructor.
|
||||
};
|
||||
|
||||
|
||||
var SlideScrollManager = function(notebook) {
|
||||
// Public constructor.
|
||||
};
|
||||
|
||||
/*// Scroll the document.
|
||||
//
|
||||
// Parameters
|
||||
// ----------
|
||||
// delta: integer
|
||||
// direction to scroll the document. Positive is downwards.
|
||||
|
||||
// If one or more slides exist, scroll to the slide.
|
||||
var $slide_cells = $('.slideshow-slide');
|
||||
@ -66,19 +164,13 @@ define([], function(){
|
||||
} else {
|
||||
this.scroll_some(delta);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
ScrollManager.prototype.scroll_to = function(destination) {
|
||||
// Scroll to an element in the notebook.
|
||||
$('#notebook').animate({'scrollTop': $(destination).offset().top + $('#notebook').scrollTop() - $('#notebook').offset().top}, this.animation_speed);
|
||||
};
|
||||
|
||||
ScrollManager.prototype.scroll_some = function(pages) {
|
||||
// Scroll up or down a given number of pages.
|
||||
$('#notebook').animate({'scrollTop': $('#notebook').scrollTop() + pages * $('#notebook').height()}, this.animation_speed);
|
||||
};
|
||||
}*/
|
||||
|
||||
// Return naemspace for require.js loads
|
||||
return ScrollManager;
|
||||
return {
|
||||
'ScrollSelector': ScrollSelector,
|
||||
'ScrollManager': ScrollManager,
|
||||
'SlideScrollManager': SlideScrollManager,
|
||||
'HeadingScrollManager': HeadingScrollManager
|
||||
};
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user