##// END OF EJS Templates
Merge pull request #5268 from ellisonbg/cmd-mode...
Brian E. Granger -
r15710:c66eef79 merge
parent child Browse files
Show More
@@ -84,7 +84,6 b' var IPython = (function (IPython) {'
84 help_index : 'aa',
84 help_index : 'aa',
85 handler : function (event) {
85 handler : function (event) {
86 IPython.notebook.command_mode();
86 IPython.notebook.command_mode();
87 IPython.notebook.focus_cell();
88 return false;
87 return false;
89 }
88 }
90 },
89 },
@@ -93,7 +92,6 b' var IPython = (function (IPython) {'
93 help_index : 'ab',
92 help_index : 'ab',
94 handler : function (event) {
93 handler : function (event) {
95 IPython.notebook.command_mode();
94 IPython.notebook.command_mode();
96 IPython.notebook.focus_cell();
97 return false;
95 return false;
98 }
96 }
99 },
97 },
@@ -120,11 +120,11 b' var IPython = (function (IPython) {'
120 });
120 });
121
121
122 $([IPython.events]).on('edit_mode.Cell', function (event, data) {
122 $([IPython.events]).on('edit_mode.Cell', function (event, data) {
123 that.handle_edit_mode(that.find_cell_index(data.cell));
123 that.handle_edit_mode(data.cell);
124 });
124 });
125
125
126 $([IPython.events]).on('command_mode.Cell', function (event, data) {
126 $([IPython.events]).on('command_mode.Cell', function (event, data) {
127 that.command_mode();
127 that.handle_command_mode(data.cell);
128 });
128 });
129
129
130 $([IPython.events]).on('status_autorestarting.Kernel', function () {
130 $([IPython.events]).on('status_autorestarting.Kernel', function () {
@@ -461,6 +461,11 b' var IPython = (function (IPython) {'
461 if (this.is_valid_cell_index(index)) {
461 if (this.is_valid_cell_index(index)) {
462 var sindex = this.get_selected_index();
462 var sindex = this.get_selected_index();
463 if (sindex !== null && index !== sindex) {
463 if (sindex !== null && index !== sindex) {
464 // If we are about to select a different cell, make sure we are
465 // first in command mode.
466 if (this.mode !== 'command') {
467 this.command_mode();
468 }
464 this.get_cell(sindex).unselect();
469 this.get_cell(sindex).unselect();
465 }
470 }
466 var cell = this.get_cell(index);
471 var cell = this.get_cell(index);
@@ -523,20 +528,14 b' var IPython = (function (IPython) {'
523 };
528 };
524
529
525 /**
530 /**
526 * Make the notebook enter command mode.
531 * Handle when a a cell blurs and the notebook should enter command mode.
527 *
532 *
528 * @method command_mode
533 * @method handle_command_mode
534 * @param [cell] {Cell} Cell to enter command mode on.
529 **/
535 **/
530 Notebook.prototype.command_mode = function () {
536 Notebook.prototype.handle_command_mode = function (cell) {
531 // Make sure there isn't an edit mode cell lingering around.
532 var cell = this.get_cell(this.get_edit_index());
533 if (cell) {
534 cell.command_mode();
535 }
536
537 // Notify the keyboard manager if this is a change of mode for the
538 // notebook as a whole.
539 if (this.mode !== 'command') {
537 if (this.mode !== 'command') {
538 cell.command_mode();
540 this.mode = 'command';
539 this.mode = 'command';
541 $([IPython.events]).trigger('command_mode.Notebook');
540 $([IPython.events]).trigger('command_mode.Notebook');
542 IPython.keyboard_manager.command_mode();
541 IPython.keyboard_manager.command_mode();
@@ -544,20 +543,28 b' var IPython = (function (IPython) {'
544 };
543 };
545
544
546 /**
545 /**
546 * Make the notebook enter command mode.
547 *
548 * @method command_mode
549 **/
550 Notebook.prototype.command_mode = function () {
551 var cell = this.get_cell(this.get_edit_index());
552 if (cell && this.mode !== 'command') {
553 // We don't call cell.command_mode, but rather call cell.focus_cell()
554 // which will blur and CM editor and trigger the call to
555 // handle_command_mode.
556 cell.focus_cell();
557 }
558 };
559
560 /**
547 * Handle when a cell fires it's edit_mode event.
561 * Handle when a cell fires it's edit_mode event.
548 *
562 *
549 * @method handle_edit_mode
563 * @method handle_edit_mode
550 * @param [index] {int} Cell index to select. If no index is provided,
564 * @param [cell] {Cell} Cell to enter edit mode on.
551 * the current selected cell is used.
552 **/
565 **/
553 Notebook.prototype.handle_edit_mode = function (index) {
566 Notebook.prototype.handle_edit_mode = function (cell) {
554 // Make sure the cell exists.
567 if (cell && this.mode !== 'edit') {
555 var cell = this.get_cell(index);
556 if (cell === null) { return; }
557
558 // Set the cell to edit mode and notify the keyboard manager if this
559 // is a change of mode for the notebook as a whole.
560 if (this.mode !== 'edit') {
561 cell.edit_mode();
568 cell.edit_mode();
562 this.mode = 'edit';
569 this.mode = 'edit';
563 $([IPython.events]).trigger('edit_mode.Notebook');
570 $([IPython.events]).trigger('edit_mode.Notebook');
@@ -569,17 +576,10 b' var IPython = (function (IPython) {'
569 * Make a cell enter edit mode.
576 * Make a cell enter edit mode.
570 *
577 *
571 * @method edit_mode
578 * @method edit_mode
572 * @param [index] {int} Cell index to select. If no index is provided,
573 * the current selected cell is used.
574 **/
579 **/
575 Notebook.prototype.edit_mode = function (index) {
580 Notebook.prototype.edit_mode = function () {
576 if (index===undefined) {
581 var cell = this.get_selected_cell();
577 index = this.get_selected_index();
582 if (cell && this.mode !== 'edit') {
578 }
579 // Make sure the cell exists.
580 var cell = this.get_cell(index);
581 if (cell === null) { return; }
582 if (cell.mode != 'edit') {
583 cell.unrender();
583 cell.unrender();
584 cell.focus_editor();
584 cell.focus_editor();
585 }
585 }
@@ -1453,7 +1453,6 b' var IPython = (function (IPython) {'
1453 var cell_index = this.find_cell_index(cell);
1453 var cell_index = this.find_cell_index(cell);
1454
1454
1455 cell.execute();
1455 cell.execute();
1456 cell.focus_cell();
1457 this.command_mode();
1456 this.command_mode();
1458 this.set_dirty(true);
1457 this.set_dirty(true);
1459 };
1458 };
@@ -1471,15 +1470,19 b' var IPython = (function (IPython) {'
1471
1470
1472 // If we are at the end always insert a new cell and return
1471 // If we are at the end always insert a new cell and return
1473 if (cell_index === (this.ncells()-1)) {
1472 if (cell_index === (this.ncells()-1)) {
1473 this.command_mode();
1474 this.insert_cell_below('code');
1474 this.insert_cell_below('code');
1475 this.edit_mode(cell_index+1);
1475 this.select(cell_index+1);
1476 this.edit_mode();
1476 this.scroll_to_bottom();
1477 this.scroll_to_bottom();
1477 this.set_dirty(true);
1478 this.set_dirty(true);
1478 return;
1479 return;
1479 }
1480 }
1480
1481
1482 this.command_mode();
1481 this.insert_cell_below('code');
1483 this.insert_cell_below('code');
1482 this.edit_mode(cell_index+1);
1484 this.select(cell_index+1);
1485 this.edit_mode();
1483 this.set_dirty(true);
1486 this.set_dirty(true);
1484 };
1487 };
1485
1488
@@ -1497,16 +1500,17 b' var IPython = (function (IPython) {'
1497
1500
1498 // If we are at the end always insert a new cell and return
1501 // If we are at the end always insert a new cell and return
1499 if (cell_index === (this.ncells()-1)) {
1502 if (cell_index === (this.ncells()-1)) {
1503 this.command_mode();
1500 this.insert_cell_below('code');
1504 this.insert_cell_below('code');
1501 this.edit_mode(cell_index+1);
1505 this.select(cell_index+1);
1506 this.edit_mode();
1502 this.scroll_to_bottom();
1507 this.scroll_to_bottom();
1503 this.set_dirty(true);
1508 this.set_dirty(true);
1504 return;
1509 return;
1505 }
1510 }
1506
1511
1507 this.select(cell_index+1);
1508 this.get_cell(cell_index+1).focus_cell();
1509 this.command_mode();
1512 this.command_mode();
1513 this.select(cell_index+1);
1510 this.set_dirty(true);
1514 this.set_dirty(true);
1511 };
1515 };
1512
1516
@@ -1547,6 +1551,7 b' var IPython = (function (IPython) {'
1547 * @param {Number} end Index of the last cell to execute (exclusive)
1551 * @param {Number} end Index of the last cell to execute (exclusive)
1548 */
1552 */
1549 Notebook.prototype.execute_cell_range = function (start, end) {
1553 Notebook.prototype.execute_cell_range = function (start, end) {
1554 this.command_mode();
1550 for (var i=start; i<end; i++) {
1555 for (var i=start; i<end; i++) {
1551 this.select(i);
1556 this.select(i);
1552 this.execute_cell();
1557 this.execute_cell();
@@ -2041,7 +2046,7 b' var IPython = (function (IPython) {'
2041 this.edit_mode(0);
2046 this.edit_mode(0);
2042 } else {
2047 } else {
2043 this.select(0);
2048 this.select(0);
2044 this.command_mode();
2049 this.handle_command_mode(this.get_cell(0));
2045 }
2050 }
2046 this.set_dirty(false);
2051 this.set_dirty(false);
2047 this.scroll_to_top();
2052 this.scroll_to_top();
General Comments 0
You need to be logged in to leave comments. Login now