Skip to content

Instantly share code, notes, and snippets.

@jdfreder
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdfreder/e2bf6c6c6beadf0a4477 to your computer and use it in GitHub Desktop.
Save jdfreder/e2bf6c6c6beadf0a4477 to your computer and use it in GitHub Desktop.
Space and shift-space H1 scrolling in the notebook.
%%javascript
window.hcell = 0;
var delta_header_scroll = function(delta) {
window.hcell += delta;
var $h1cells = $('h1 a');
window.hcell = Math.max(0, Math.min($h1cells.length-1, window.hcell));
setTimeout(function(){$h1cells[window.hcell].scrollIntoView(true);}, 0);
};
IPython.keyboard_manager.command_shortcuts.add_shortcuts({
'space': {
help: "Scroll down to next H1 cell",
handler: function(event) {
delta_header_scroll(1);
},
},
'shift-space': {
help: "Scroll up to previous H1 cell",
handler: function(event) {
delta_header_scroll(-1);
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment