mirror of
https://github.com/jupyter/notebook.git
synced 2024-12-21 04:10:17 +08:00
update example on how to bind keyboard shortcut
This commit is contained in:
parent
37d4ede57e
commit
a7dc324bba
@ -11,7 +11,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Starting with IPython 2.0 keyboard shortcuts in command and edit mode are fully customizable. These customizations are made using the IPython JavaScript API. Here is an example that makes the `r` key available for running a cell:"
|
||||
"Starting with IPython 2.0 keyboard shortcuts in command and edit mode are fully customizable. These customizations are made using the Jupyter JavaScript API. Here is an example that makes the `r` key available for running a cell:"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -24,7 +24,7 @@
|
||||
"source": [
|
||||
"%%javascript\n",
|
||||
"\n",
|
||||
"IPython.keyboard_manager.command_shortcuts.add_shortcut('r', {\n",
|
||||
"Jupyter.keyboard_manager.command_shortcuts.add_shortcut('r', {\n",
|
||||
" help : 'run cell',\n",
|
||||
" help_index : 'zz',\n",
|
||||
" handler : function (event) {\n",
|
||||
@ -34,6 +34,13 @@
|
||||
");"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"The keypress `r` in command mode is by default bound to change the type of a cell ro `raw`. This action will thus be unavaillable from the keyboard now."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@ -55,7 +62,7 @@
|
||||
"source": [
|
||||
"%%javascript\n",
|
||||
"\n",
|
||||
"IPython.keyboard_manager.command_shortcuts.add_shortcut('r', function (event) {\n",
|
||||
"Jupyter.keyboard_manager.command_shortcuts.add_shortcut('r', function (event) {\n",
|
||||
" IPython.notebook.execute_cell();\n",
|
||||
" return false;\n",
|
||||
"});"
|
||||
@ -78,14 +85,36 @@
|
||||
"source": [
|
||||
"%%javascript\n",
|
||||
"\n",
|
||||
"IPython.keyboard_manager.command_shortcuts.remove_shortcut('r');"
|
||||
"Jupyter.keyboard_manager.command_shortcuts.remove_shortcut('r');"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"If you want your keyboard shortcuts to be active for all of your notebooks, put the above API calls into your `<profile>/static/custom/custom.js` file."
|
||||
"If you want your keyboard shortcuts to be active for all of your notebooks, put the above API calls into your `custom.js` file."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"source": [
|
||||
"Of course we provide name for majority of existing action so that you do not have to re-write everything, here is for example how to bind `r` back to it's initial behavior:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%%javascript\n",
|
||||
"\n",
|
||||
"Jupyter.keyboard_manager.command_shortcuts.add_shortcut('r', 'ipython.change-selected-cell-to-raw-cell');"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user