From 6120c07c4d172ec6cc348ea3d40c1287f59a267e Mon Sep 17 00:00:00 2001 From: fawce Date: Fri, 27 Jan 2012 14:18:48 -0500 Subject: [PATCH] added key handler for control-s to notebook, seems to work pretty well --- IPython/frontend/html/notebook/static/js/codecell.js | 5 +++-- IPython/frontend/html/notebook/static/js/notebook.js | 8 +++++++- IPython/frontend/html/notebook/static/js/textcell.js | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/IPython/frontend/html/notebook/static/js/codecell.js b/IPython/frontend/html/notebook/static/js/codecell.js index 9cf29bde1..2988dec85 100644 --- a/IPython/frontend/html/notebook/static/js/codecell.js +++ b/IPython/frontend/html/notebook/static/js/codecell.js @@ -70,7 +70,7 @@ var IPython = (function (IPython) { if (this.read_only){ return false; } - + // note that we are comparing and setting the time to wait at each key press. // a better wqy might be to generate a new function on each time change and // assign it to CodeCell.prototype.request_tooltip_after_time @@ -82,7 +82,8 @@ var IPython = (function (IPython) { if(event.type === 'keydown' ){ that.remove_and_cancel_tooltip(); } - + + if (event.keyCode === 13 && (event.shiftKey || event.ctrlKey)) { // Always ignore shift-enter in CodeMirror as we handle it. return true; diff --git a/IPython/frontend/html/notebook/static/js/notebook.js b/IPython/frontend/html/notebook/static/js/notebook.js index b207ad31b..5610aae0e 100644 --- a/IPython/frontend/html/notebook/static/js/notebook.js +++ b/IPython/frontend/html/notebook/static/js/notebook.js @@ -62,7 +62,13 @@ var IPython = (function (IPython) { $(document).keydown(function (event) { // console.log(event); if (that.read_only) return true; - if (event.which === 27) { + + // Save (CTRL+S) or (AppleKey+S) + //metaKey = applekey on mac + if ((event.ctrlKey || event.metaKey) && event.keyCode==83) { + IPython.save_widget.save_notebook(); + event.preventDefault(); + } else if (event.which === 27) { // Intercept escape at highest level to avoid closing // websocket connection with firefox event.preventDefault(); diff --git a/IPython/frontend/html/notebook/static/js/textcell.js b/IPython/frontend/html/notebook/static/js/textcell.js index 96230d6de..aacfddf05 100644 --- a/IPython/frontend/html/notebook/static/js/textcell.js +++ b/IPython/frontend/html/notebook/static/js/textcell.js @@ -67,7 +67,7 @@ var IPython = (function (IPython) { // 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;