##// END OF EJS Templates
Adding basic examples notebook about modal editing.
Brian E. Granger -
Show More
@@ -0,0 +1,378 b''
1 {
2 "metadata": {
3 "name": ""
4 },
5 "nbformat": 3,
6 "nbformat_minor": 0,
7 "worksheets": [
8 {
9 "cells": [
10 {
11 "cell_type": "heading",
12 "level": 1,
13 "metadata": {},
14 "source": [
15 "User Experience"
16 ]
17 },
18 {
19 "cell_type": "markdown",
20 "metadata": {},
21 "source": [
22 "This notebook describes the user experience of the IPython Notebook. This includes both mouse and keyboard based navigation and interaction.\n",
23 "\n",
24 "<div class=\"alert\" style=\"margin: 10px\">\n",
25 "As of IPython 2.0, the user experience has changed significantly. Because of this we highly recommend existing users to review this information after upgrading to IPython 2.0. All new users of IPython should review this information as well.\n",
26 "</div>"
27 ]
28 },
29 {
30 "cell_type": "heading",
31 "level": 2,
32 "metadata": {},
33 "source": [
34 "Modal editor"
35 ]
36 },
37 {
38 "cell_type": "markdown",
39 "metadata": {},
40 "source": [
41 "Starting with IPython 2.0, the IPython Notebook has a modal user experience. This means that the keyboard does different things depending on which mode the Notebook is in. There are two modes:"
42 ]
43 },
44 {
45 "cell_type": "heading",
46 "level": 3,
47 "metadata": {},
48 "source": [
49 "Edit mode"
50 ]
51 },
52 {
53 "cell_type": "markdown",
54 "metadata": {},
55 "source": [
56 "Edit mode is indicated by a green cell border and a prompt showing in the editor area:\n",
57 "\n",
58 "<img src=\"edit_mode.png\">\n",
59 "\n",
60 "When a cell is in edit mode, you can type into the cell, like a normal text editor.\n",
61 "\n",
62 "<div class=\"alert alert-success\" style=\"margin: 10px\">\n",
63 "Enter edit mode by pressing `enter` or using the mouse to click on a cell's editor area.\n",
64 "</div>"
65 ]
66 },
67 {
68 "cell_type": "heading",
69 "level": 3,
70 "metadata": {},
71 "source": [
72 "Command mode"
73 ]
74 },
75 {
76 "cell_type": "markdown",
77 "metadata": {},
78 "source": [
79 "Command mode is indicated by a grey cell border:\n",
80 "\n",
81 "<img src=\"command_mode.png\">\n",
82 "\n",
83 "When you are in command mode, you are able to edit the notebook as a whole, but not type into individual cells. Most importantly, in command mode, the keyboard is mapped to a set of shortcuts that let you perform notebook and cell actions efficiently. For example, if you are in command mode and you press `c`, you will copy the current cell - no modifier is needed.\n",
84 "\n",
85 "<div class=\"alert alert-error\" style=\"margin: 10px\">\n",
86 "Don't try to type into a cell in command mode; unexpected things will happen!\n",
87 "</div>\n",
88 "\n",
89 "<div class=\"alert alert-success\" style=\"margin: 10px\">\n",
90 "Enter command mode by pressing `esc` or using the mouse to click *outside* a cell's editor area.\n",
91 "</div>"
92 ]
93 },
94 {
95 "cell_type": "heading",
96 "level": 2,
97 "metadata": {},
98 "source": [
99 "Mouse navigation"
100 ]
101 },
102 {
103 "cell_type": "markdown",
104 "metadata": {},
105 "source": [
106 "All navigation and actions in the Notebook are available using the mouse through the menubar and toolbar, which are both above the main Notebook area:\n",
107 "\n",
108 "<img src=\"menubar_toolbar.png\">"
109 ]
110 },
111 {
112 "cell_type": "markdown",
113 "metadata": {},
114 "source": [
115 "The first idea of mouse based navigation is that **cells can be selected by clicking on them.** The currently selected cell gets a grey or green border depending on whether the notebook is in edit or command mode. If you click inside a cell's editor area, you will enter edit mode. If you click on the prompt or output area of a cell you will enter command mode.\n",
116 "\n",
117 "If you are running this notebook in a live session (not on http://nbviewer.ipython.org) try selecting different cells and going between edit and command mode. Try typing into a cell."
118 ]
119 },
120 {
121 "cell_type": "markdown",
122 "metadata": {},
123 "source": [
124 "The second idea of mouse based navigation is that **cell actions usually apply to the currently selected cell**. Thus if you want to run the code in a cell, you would select it and click the \"Play\" button in the toolbar or the \"Cell:Run\" menu item. Similarly, to copy a cell you would select it and click the \"Copy\" button in the toolbar or the \"Edit:Copy\" menu item. With this simple pattern, you should be able to do most everything you need with the mouse.\n",
125 "\n",
126 "Markdown and heading cells have one other state that can be modified with the mouse. These cells can either be rendered or unrendered. When they are rendered, you will see a nice formatted representation of the cell's contents. When they are unrendered, you will see the raw text source of the cell. To render the selected cell with the mouse, click the \"Play\" button in the toolbar or the \"Cell:Run\" menu item. To unrender the selected cell, double click on the cell."
127 ]
128 },
129 {
130 "cell_type": "heading",
131 "level": 2,
132 "metadata": {},
133 "source": [
134 "Keyboard Navigation"
135 ]
136 },
137 {
138 "cell_type": "markdown",
139 "metadata": {},
140 "source": [
141 "The modal user experience of the IPython Notebook has been optimized for efficient keyboard usage. This is made possible by having two different sets of keyboard shortcuts: one set that is active in edit mode and another in command mode.\n",
142 "\n",
143 "The most important keyboard shortcuts are `enter`, which enters edit mode, and `esc`, which enters command mode.\n",
144 "\n",
145 "In edit mode, most of the keyboard is dedicated to typing into the cell's editor. Thus, in edit mode there are relatively few shortcuts:"
146 ]
147 },
148 {
149 "cell_type": "code",
150 "collapsed": false,
151 "input": [
152 "display_edit_shortcuts()"
153 ],
154 "language": "python",
155 "metadata": {},
156 "outputs": [
157 {
158 "html": [
159 "<div class=\"hbox\"><div class=\"box-flex0\"><div class=\"quickhelp\"><span class=\"shortcut_key\">esc</span><span class=\"shortcut_descr\"> : command mode</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">ctrl+m</span><span class=\"shortcut_descr\"> : command mode</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">shift+enter</span><span class=\"shortcut_descr\"> : run cell</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">ctrl+enter</span><span class=\"shortcut_descr\"> : run cell, select below</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">alt+enter</span><span class=\"shortcut_descr\"> : run cell, insert below</span></div></div><div class=\"box-flex0\"><div class=\"quickhelp\"><span class=\"shortcut_key\">up</span><span class=\"shortcut_descr\"> : select previous cell</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">down</span><span class=\"shortcut_descr\"> : select next cell</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">alt+-</span><span class=\"shortcut_descr\"> : split cell</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">meta+s</span><span class=\"shortcut_descr\"> : save notebook</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">ctrl+s</span><span class=\"shortcut_descr\"> : save notebook</span></div></div></div>"
160 ],
161 "output_type": "display_data"
162 },
163 {
164 "javascript": [
165 "var help = IPython.quick_help.build_edit_help();\n",
166 "help.children().first().remove();\n",
167 "this.append_output({output_type: 'display_data', html: help.html()});"
168 ],
169 "metadata": {},
170 "output_type": "display_data",
171 "text": [
172 "<IPython.core.display.Javascript at 0x10e441250>"
173 ]
174 }
175 ],
176 "prompt_number": 14
177 },
178 {
179 "cell_type": "markdown",
180 "metadata": {},
181 "source": [
182 "There are two other keyboard shortcuts in edit mode that are not listed here:\n",
183 "\n",
184 "* `tab`: trigger \"tab\" completion\n",
185 "* `shift+tab`: open the tooltip"
186 ]
187 },
188 {
189 "cell_type": "markdown",
190 "metadata": {},
191 "source": [
192 "In command mode, the entire keyboard is available for shortcuts:"
193 ]
194 },
195 {
196 "cell_type": "code",
197 "collapsed": false,
198 "input": [
199 "display_command_shortcuts()"
200 ],
201 "language": "python",
202 "metadata": {},
203 "outputs": [
204 {
205 "html": [
206 "<div class=\"hbox\"><div class=\"box-flex0\"><div class=\"quickhelp\"><span class=\"shortcut_key\">enter</span><span class=\"shortcut_descr\"> : edit mode</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">shift+enter</span><span class=\"shortcut_descr\"> : run cell</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">ctrl+enter</span><span class=\"shortcut_descr\"> : run cell, select below</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">alt+enter</span><span class=\"shortcut_descr\"> : run cell, insert below</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">y</span><span class=\"shortcut_descr\"> : to code</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">m</span><span class=\"shortcut_descr\"> : to markdown</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">t</span><span class=\"shortcut_descr\"> : to raw</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">1</span><span class=\"shortcut_descr\"> : to heading 1</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">2</span><span class=\"shortcut_descr\"> : to heading 2</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">3</span><span class=\"shortcut_descr\"> : to heading 3</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">4</span><span class=\"shortcut_descr\"> : to heading 4</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">5</span><span class=\"shortcut_descr\"> : to heading 5</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">6</span><span class=\"shortcut_descr\"> : to heading 6</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">up</span><span class=\"shortcut_descr\"> : select previous cell</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">down</span><span class=\"shortcut_descr\"> : select next cell</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">k</span><span class=\"shortcut_descr\"> : select previous cell</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">j</span><span class=\"shortcut_descr\"> : select next cell</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">ctrl+k</span><span class=\"shortcut_descr\"> : move cell up</span></div></div><div class=\"box-flex0\"><div class=\"quickhelp\"><span class=\"shortcut_key\">ctrl+j</span><span class=\"shortcut_descr\"> : move cell down</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">a</span><span class=\"shortcut_descr\"> : insert cell above</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">b</span><span class=\"shortcut_descr\"> : insert cell below</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">x</span><span class=\"shortcut_descr\"> : cut cell</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">c</span><span class=\"shortcut_descr\"> : copy cell</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">v</span><span class=\"shortcut_descr\"> : paste cell below</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">z</span><span class=\"shortcut_descr\"> : undo last delete</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">d</span><span class=\"shortcut_descr\"> : delete cell (press twice)</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">shift+=</span><span class=\"shortcut_descr\"> : merge cell below</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">s</span><span class=\"shortcut_descr\"> : save notebook</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">meta+s</span><span class=\"shortcut_descr\"> : save notebook</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">ctrl+s</span><span class=\"shortcut_descr\"> : save notebook</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">l</span><span class=\"shortcut_descr\"> : toggle line numbers</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">o</span><span class=\"shortcut_descr\"> : toggle output</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">shift+o</span><span class=\"shortcut_descr\"> : toggle output</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">h</span><span class=\"shortcut_descr\"> : keyboard shortcuts</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">i</span><span class=\"shortcut_descr\"> : interrupt kernel</span></div><div class=\"quickhelp\"><span class=\"shortcut_key\">.</span><span class=\"shortcut_descr\"> : restart kernel</span></div></div></div>"
207 ],
208 "output_type": "display_data"
209 },
210 {
211 "javascript": [
212 "var help = IPython.quick_help.build_command_help();\n",
213 "help.children().first().remove();\n",
214 "this.append_output({output_type: 'display_data', html: help.html()});"
215 ],
216 "metadata": {},
217 "output_type": "display_data",
218 "text": [
219 "<IPython.core.display.Javascript at 0x10e441410>"
220 ]
221 }
222 ],
223 "prompt_number": 15
224 },
225 {
226 "cell_type": "markdown",
227 "metadata": {},
228 "source": [
229 "Here the rough order in which we recommend learning the command mode shortcuts:\n",
230 "\n",
231 "1. Basic navigation: `enter`, `shift-enter`, `up/k`, `down/j`\n",
232 "2. Saving the notebook: `s`\n",
233 "2. Cell types: `y`, `m`, `1-6`, `t`\n",
234 "3. Cell creation and movement: `a`, `b`, `ctrl+k`, `ctrl+j`\n",
235 "4. Cell editing: `x`, `c`, `v`, `d`, `z`, `shift+=`\n",
236 "5. Kernel operations: `i`, `.`"
237 ]
238 },
239 {
240 "cell_type": "heading",
241 "level": 2,
242 "metadata": {},
243 "source": [
244 "Keyboard shortcut customization"
245 ]
246 },
247 {
248 "cell_type": "markdown",
249 "metadata": {},
250 "source": [
251 "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:"
252 ]
253 },
254 {
255 "cell_type": "code",
256 "collapsed": false,
257 "input": [
258 "%%javascript\n",
259 "\n",
260 "IPython.keyboard_manager.command_shortcuts.add_shortcut('r', {\n",
261 " help : 'run cell',\n",
262 " help_index : 'bd',\n",
263 " handler : function (event) {\n",
264 " IPython.notebook.execute_cell();\n",
265 " return false;\n",
266 " }}\n",
267 ");"
268 ],
269 "language": "python",
270 "metadata": {},
271 "outputs": [
272 {
273 "javascript": [
274 "\n",
275 "IPython.keyboard_manager.command_shortcuts.add_shortcut('r', {\n",
276 " help : 'run cell',\n",
277 " help_index : 'bd',\n",
278 " handler : function (event) {\n",
279 " IPython.notebook.execute_cell();\n",
280 " return false;\n",
281 " }}\n",
282 ");"
283 ],
284 "metadata": {},
285 "output_type": "display_data",
286 "text": [
287 "<IPython.core.display.Javascript at 0x10e441390>"
288 ]
289 }
290 ],
291 "prompt_number": 17
292 },
293 {
294 "cell_type": "markdown",
295 "metadata": {},
296 "source": [
297 "There are a couple of points to mention about this API:\n",
298 "\n",
299 "* The `help_index` field is used to sort the shortcuts in the Keyboard Shortcuts help dialog.\n",
300 "* When a handler returns `false` it indicates that the event should stop propagating and the default action should not be performed. For further details about the `event` object or event handling, see the jQuery docs.\n",
301 "* If you don't need a `help` or `help_index` field, you can simply pass a function as the second argument to `add_shortcut`.\n",
302 "\n",
303 "Likewise, to remove a shortcut, use `remove_shortcut`:"
304 ]
305 },
306 {
307 "cell_type": "code",
308 "collapsed": false,
309 "input": [
310 "%%javascript\n",
311 "\n",
312 "IPython.keyboard_manager.command_shortcuts.remove_shortcut('r');"
313 ],
314 "language": "python",
315 "metadata": {},
316 "outputs": [
317 {
318 "javascript": [
319 "\n",
320 "IPython.keyboard_manager.command_shortcuts.remove_shortcut('r');"
321 ],
322 "metadata": {},
323 "output_type": "display_data",
324 "text": [
325 "<IPython.core.display.Javascript at 0x10e441250>"
326 ]
327 }
328 ],
329 "prompt_number": 18
330 },
331 {
332 "cell_type": "markdown",
333 "metadata": {},
334 "source": [
335 "If you want your keyboard shortcuts to be active for all of your notebooks, put the above API calls into your `custom.js` file."
336 ]
337 },
338 {
339 "cell_type": "heading",
340 "level": 2,
341 "metadata": {},
342 "source": [
343 "Utilities"
344 ]
345 },
346 {
347 "cell_type": "markdown",
348 "metadata": {},
349 "source": [
350 "We use the following functions to generate the keyboard shortcut listings above."
351 ]
352 },
353 {
354 "cell_type": "code",
355 "collapsed": false,
356 "input": [
357 "from IPython.display import Javascript, display\n",
358 "\n",
359 "t = \"\"\"var help = IPython.quick_help.build_{0}_help();\n",
360 "help.children().first().remove();\n",
361 "this.append_output({{output_type: 'display_data', html: help.html()}});\"\"\"\n",
362 "\n",
363 "def display_command_shortcuts():\n",
364 " display(Javascript(t.format('command')))\n",
365 "\n",
366 "def display_edit_shortcuts():\n",
367 " display(Javascript(t.format('edit'))) "
368 ],
369 "language": "python",
370 "metadata": {},
371 "outputs": [],
372 "prompt_number": 12
373 }
374 ],
375 "metadata": {}
376 }
377 ]
378 } No newline at end of file
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
General Comments 0
You need to be logged in to leave comments. Login now