##// END OF EJS Templates
Make sure we are in command mode before we select a new cell.
Brian E. Granger -
Show More
@@ -457,6 +457,11 b' var IPython = (function (IPython) {'
457 if (this.is_valid_cell_index(index)) {
457 if (this.is_valid_cell_index(index)) {
458 var sindex = this.get_selected_index();
458 var sindex = this.get_selected_index();
459 if (sindex !== null && index !== sindex) {
459 if (sindex !== null && index !== sindex) {
460 // If we are about to select a different cell, make sure we are
461 // first in command mode.
462 if (this.mode !== 'command') {
463 this.command_mode();
464 }
460 this.get_cell(sindex).unselect();
465 this.get_cell(sindex).unselect();
461 }
466 }
462 var cell = this.get_cell(index);
467 var cell = this.get_cell(index);
@@ -526,7 +531,7 b' var IPython = (function (IPython) {'
526 **/
531 **/
527 Notebook.prototype.handle_command_mode = function (cell) {
532 Notebook.prototype.handle_command_mode = function (cell) {
528 if (this.mode !== 'command') {
533 if (this.mode !== 'command') {
529 cell.command_mode(); // TODO: is this OK here?
534 cell.command_mode();
530 this.mode = 'command';
535 this.mode = 'command';
531 $([IPython.events]).trigger('command_mode.Notebook');
536 $([IPython.events]).trigger('command_mode.Notebook');
532 IPython.keyboard_manager.command_mode();
537 IPython.keyboard_manager.command_mode();
@@ -555,7 +560,7 b' var IPython = (function (IPython) {'
555 * @param [cell] {Cell} Cell to enter edit mode on.
560 * @param [cell] {Cell} Cell to enter edit mode on.
556 **/
561 **/
557 Notebook.prototype.handle_edit_mode = function (cell) {
562 Notebook.prototype.handle_edit_mode = function (cell) {
558 if (this.mode !== 'edit') {
563 if (cell && this.mode !== 'edit') {
559 cell.edit_mode();
564 cell.edit_mode();
560 this.mode = 'edit';
565 this.mode = 'edit';
561 $([IPython.events]).trigger('edit_mode.Notebook');
566 $([IPython.events]).trigger('edit_mode.Notebook');
@@ -567,17 +572,10 b' var IPython = (function (IPython) {'
567 * Make a cell enter edit mode.
572 * Make a cell enter edit mode.
568 *
573 *
569 * @method edit_mode
574 * @method edit_mode
570 * @param [index] {int} Cell index to select. If no index is provided,
571 * the current selected cell is used.
572 **/
575 **/
573 Notebook.prototype.edit_mode = function (index) {
576 Notebook.prototype.edit_mode = function () {
574 if (index===undefined) {
577 var cell = this.get_selected_cell();
575 index = this.get_selected_index();
578 if (cell && this.mode !== 'edit') {
576 }
577 // Make sure the cell exists.
578 var cell = this.get_cell(index);
579 if (cell === null) { return; }
580 if (cell.mode != 'edit') {
581 cell.unrender();
579 cell.unrender();
582 cell.focus_editor();
580 cell.focus_editor();
583 }
581 }
@@ -1468,15 +1466,19 b' var IPython = (function (IPython) {'
1468
1466
1469 // If we are at the end always insert a new cell and return
1467 // If we are at the end always insert a new cell and return
1470 if (cell_index === (this.ncells()-1)) {
1468 if (cell_index === (this.ncells()-1)) {
1469 this.command_mode();
1471 this.insert_cell_below('code');
1470 this.insert_cell_below('code');
1472 this.edit_mode(cell_index+1);
1471 this.select(cell_index+1);
1472 this.edit_mode();
1473 this.scroll_to_bottom();
1473 this.scroll_to_bottom();
1474 this.set_dirty(true);
1474 this.set_dirty(true);
1475 return;
1475 return;
1476 }
1476 }
1477
1477
1478 this.command_mode();
1478 this.insert_cell_below('code');
1479 this.insert_cell_below('code');
1479 this.edit_mode(cell_index+1);
1480 this.select(cell_index+1);
1481 this.edit_mode();
1480 this.set_dirty(true);
1482 this.set_dirty(true);
1481 };
1483 };
1482
1484
@@ -1494,15 +1496,17 b' var IPython = (function (IPython) {'
1494
1496
1495 // If we are at the end always insert a new cell and return
1497 // If we are at the end always insert a new cell and return
1496 if (cell_index === (this.ncells()-1)) {
1498 if (cell_index === (this.ncells()-1)) {
1499 this.command_mode();
1497 this.insert_cell_below('code');
1500 this.insert_cell_below('code');
1498 this.edit_mode(cell_index+1);
1501 this.select(cell_index+1);
1502 this.edit_mode();
1499 this.scroll_to_bottom();
1503 this.scroll_to_bottom();
1500 this.set_dirty(true);
1504 this.set_dirty(true);
1501 return;
1505 return;
1502 }
1506 }
1503
1507
1504 this.select(cell_index+1);
1505 this.command_mode();
1508 this.command_mode();
1509 this.select(cell_index+1);
1506 this.set_dirty(true);
1510 this.set_dirty(true);
1507 };
1511 };
1508
1512
@@ -1543,6 +1547,7 b' var IPython = (function (IPython) {'
1543 * @param {Number} end Index of the last cell to execute (exclusive)
1547 * @param {Number} end Index of the last cell to execute (exclusive)
1544 */
1548 */
1545 Notebook.prototype.execute_cell_range = function (start, end) {
1549 Notebook.prototype.execute_cell_range = function (start, end) {
1550 this.command_mode();
1546 for (var i=start; i<end; i++) {
1551 for (var i=start; i<end; i++) {
1547 this.select(i);
1552 this.select(i);
1548 this.execute_cell();
1553 this.execute_cell();
General Comments 0
You need to be logged in to leave comments. Login now