##// END OF EJS Templates
Updating cell logic....
Brian Granger -
Show More
@@ -14,6 +14,7 b' var IPython = (function (IPython) {'
14 var utils = IPython.utils;
14 var utils = IPython.utils;
15
15
16 var Cell = function (notebook) {
16 var Cell = function (notebook) {
17 this.placeholder = this.placeholder || '';
17 this.notebook = notebook;
18 this.notebook = notebook;
18 this.read_only = false;
19 this.read_only = false;
19 if (notebook){
20 if (notebook){
@@ -93,6 +93,24 b' var IPython = (function (IPython) {'
93 var cursor = editor.getCursor();
93 var cursor = editor.getCursor();
94 var pre_cursor = editor.getRange({line:cursor.line,ch:0},cursor).trim()+'(';
94 var pre_cursor = editor.getRange({line:cursor.line,ch:0},cursor).trim()+'(';
95 that.request_tooltip_after_time(pre_cursor,tooltip_wait_time);
95 that.request_tooltip_after_time(pre_cursor,tooltip_wait_time);
96 } else if (event.which === 38) {
97 // If we are not at the top, let CM handle the up arrow and
98 // prevent the global keydown handler from handling it.
99 if (!that.at_top()) {
100 event.stop();
101 return false;
102 } else {
103 return true;
104 };
105 } else if (event.which === 40) {
106 // If we are not at the bottom, let CM handle the down arrow and
107 // prevent the global keydown handler from handling it.
108 if (!that.at_bottom()) {
109 event.stop();
110 return false;
111 } else {
112 return true;
113 };
96 } else if (event.keyCode === 9 && event.type == 'keydown') {
114 } else if (event.keyCode === 9 && event.type == 'keydown') {
97 // Tab completion.
115 // Tab completion.
98 var cur = editor.getCursor();
116 var cur = editor.getCursor();
@@ -512,8 +512,7 b' var IPython = (function (IPython) {'
512 var i = this.index_or_selected(index);
512 var i = this.index_or_selected(index);
513 var source_element = this.cell_elements().eq(i);
513 var source_element = this.cell_elements().eq(i);
514 var source_cell = source_element.data("cell");
514 var source_cell = source_element.data("cell");
515 if (source_cell instanceof IPython.HTMLCell ||
515 if (!(source_cell instanceof IPython.CodeCell)) {
516 source_cell instanceof IPython.MarkdownCell) {
517 this.insert_code_cell_below(i);
516 this.insert_code_cell_below(i);
518 var target_cell = this.cells()[i+1];
517 var target_cell = this.cells()[i+1];
519 var text = source_cell.get_text();
518 var text = source_cell.get_text();
@@ -534,27 +533,23 b' var IPython = (function (IPython) {'
534 var source_element = this.cell_elements().eq(i);
533 var source_element = this.cell_elements().eq(i);
535 var source_cell = source_element.data("cell");
534 var source_cell = source_element.data("cell");
536 var target_cell = null;
535 var target_cell = null;
537 if (source_cell instanceof IPython.CodeCell) {
536 if (!(source_cell instanceof IPython.MarkdownCell)) {
538 this.insert_markdown_cell_below(i);
539 target_cell = this.cells()[i+1];
540 var text = source_cell.get_text();
541 } else if (source_cell instanceof IPython.HTMLCell) {
542 this.insert_markdown_cell_below(i);
537 this.insert_markdown_cell_below(i);
543 target_cell = this.cells()[i+1];
538 target_cell = this.cells()[i+1];
544 var text = source_cell.get_text();
539 var text = source_cell.get_text();
545 if (text === source_cell.placeholder) {
540 if (text === source_cell.placeholder) {
546 text = target_cell.placeholder;
541 text = target_cell.placeholder;
542 };
543 if (target_cell !== null) {
544 if (text === "") {text = target_cell.placeholder;};
545 // The edit must come before the set_text.
546 target_cell.edit();
547 target_cell.set_text(text);
548 source_element.remove();
549 target_cell.select();
547 }
550 }
548 }
551 this.dirty = true;
549 if (target_cell !== null) {
552 };
550 if (text === "") {text = target_cell.placeholder;};
551 // The edit must come before the set_text.
552 target_cell.edit();
553 target_cell.set_text(text);
554 source_element.remove();
555 target_cell.select();
556 }
557 this.dirty = true;
558 };
553 };
559
554
560
555
@@ -564,25 +559,23 b' var IPython = (function (IPython) {'
564 var source_element = this.cell_elements().eq(i);
559 var source_element = this.cell_elements().eq(i);
565 var source_cell = source_element.data("cell");
560 var source_cell = source_element.data("cell");
566 var target_cell = null;
561 var target_cell = null;
567 if (source_cell instanceof IPython.CodeCell) {
562 if (!(source_cell instanceof IPython.HTMLCell)) {
568 this.insert_html_cell_below(i);
569 target_cell = this.cells()[i+1];
570 var text = source_cell.get_text();
571 } else if (source_cell instanceof IPython.MarkdownCell) {
572 this.insert_html_cell_below(i);
563 this.insert_html_cell_below(i);
573 target_cell = this.cells()[i+1];
564 target_cell = this.cells()[i+1];
574 var text = source_cell.get_text();
565 var text = source_cell.get_text();
575 if (text === source_cell.placeholder) {
566 if (text === source_cell.placeholder) {
576 text = target_cell.placeholder;
567 text = target_cell.placeholder;
568 };
569 if (target_cell !== null) {
570 if (text === "") {text = target_cell.placeholder;};
571 // The edit must come before the set_text.
572 target_cell.edit();
573 target_cell.set_text(text);
574 source_element.remove();
575 target_cell.select();
577 }
576 }
578 }
577 this.dirty = true;
579 if (target_cell !== null) {
578 };
580 if (text === "") {text = target_cell.placeholder;};
581 target_cell.set_text(text);
582 source_element.remove();
583 target_cell.edit();
584 }
585 this.dirty = true;
586 };
579 };
587
580
588
581
@@ -629,14 +622,12 b' var IPython = (function (IPython) {'
629 var cell_data = this.clipboard;
622 var cell_data = this.clipboard;
630 if (cell_data.cell_type == 'code') {
623 if (cell_data.cell_type == 'code') {
631 new_cell = this.insert_code_cell_above();
624 new_cell = this.insert_code_cell_above();
632 new_cell.fromJSON(cell_data);
633 } else if (cell_data.cell_type === 'html') {
625 } else if (cell_data.cell_type === 'html') {
634 new_cell = this.insert_html_cell_above();
626 new_cell = this.insert_html_cell_above();
635 new_cell.fromJSON(cell_data);
636 } else if (cell_data.cell_type === 'markdown') {
627 } else if (cell_data.cell_type === 'markdown') {
637 new_cell = this.insert_markdown_cell_above();
628 new_cell = this.insert_markdown_cell_above();
638 new_cell.fromJSON(cell_data);
639 };
629 };
630 new_cell.fromJSON(cell_data);
640 this.select_next();
631 this.select_next();
641 this.delete_cell();
632 this.delete_cell();
642 };
633 };
@@ -648,14 +639,12 b' var IPython = (function (IPython) {'
648 var cell_data = this.clipboard;
639 var cell_data = this.clipboard;
649 if (cell_data.cell_type == 'code') {
640 if (cell_data.cell_type == 'code') {
650 new_cell = this.insert_code_cell_above();
641 new_cell = this.insert_code_cell_above();
651 new_cell.fromJSON(cell_data);
652 } else if (cell_data.cell_type === 'html') {
642 } else if (cell_data.cell_type === 'html') {
653 new_cell = this.insert_html_cell_above();
643 new_cell = this.insert_html_cell_above();
654 new_cell.fromJSON(cell_data);
655 } else if (cell_data.cell_type === 'markdown') {
644 } else if (cell_data.cell_type === 'markdown') {
656 new_cell = this.insert_markdown_cell_above();
645 new_cell = this.insert_markdown_cell_above();
657 new_cell.fromJSON(cell_data);
658 };
646 };
647 new_cell.fromJSON(cell_data);
659 };
648 };
660 };
649 };
661
650
@@ -665,14 +654,12 b' var IPython = (function (IPython) {'
665 var cell_data = this.clipboard;
654 var cell_data = this.clipboard;
666 if (cell_data.cell_type == 'code') {
655 if (cell_data.cell_type == 'code') {
667 new_cell = this.insert_code_cell_below();
656 new_cell = this.insert_code_cell_below();
668 new_cell.fromJSON(cell_data);
669 } else if (cell_data.cell_type === 'html') {
657 } else if (cell_data.cell_type === 'html') {
670 new_cell = this.insert_html_cell_below();
658 new_cell = this.insert_html_cell_below();
671 new_cell.fromJSON(cell_data);
672 } else if (cell_data.cell_type === 'markdown') {
659 } else if (cell_data.cell_type === 'markdown') {
673 new_cell = this.insert_markdown_cell_below();
660 new_cell = this.insert_markdown_cell_below();
674 new_cell.fromJSON(cell_data);
675 };
661 };
662 new_cell.fromJSON(cell_data);
676 };
663 };
677 };
664 };
678
665
@@ -15,7 +15,6 b' var IPython = (function (IPython) {'
15
15
16 var TextCell = function (notebook) {
16 var TextCell = function (notebook) {
17 this.code_mirror_mode = this.code_mirror_mode || 'htmlmixed';
17 this.code_mirror_mode = this.code_mirror_mode || 'htmlmixed';
18 this.placeholder = this.placeholder || '\u0000';
19 IPython.Cell.apply(this, arguments);
18 IPython.Cell.apply(this, arguments);
20 this.rendered = false;
19 this.rendered = false;
21 this.cell_type = this.cell_type || 'text';
20 this.cell_type = this.cell_type || 'text';
@@ -182,7 +181,7 b' var IPython = (function (IPython) {'
182 // HTMLCell
181 // HTMLCell
183
182
184 var HTMLCell = function (notebook) {
183 var HTMLCell = function (notebook) {
185 this.placeholder = "\u0000Type <strong>HTML</strong> and LaTeX: $\\alpha^2$";
184 this.placeholder = "Type <strong>HTML</strong> and LaTeX: $\\alpha^2$";
186 IPython.TextCell.apply(this, arguments);
185 IPython.TextCell.apply(this, arguments);
187 this.cell_type = 'html';
186 this.cell_type = 'html';
188 };
187 };
@@ -207,7 +206,7 b' var IPython = (function (IPython) {'
207 // MarkdownCell
206 // MarkdownCell
208
207
209 var MarkdownCell = function (notebook) {
208 var MarkdownCell = function (notebook) {
210 this.placeholder = "\u0000Type *Markdown* and LaTeX: $\\alpha^2$";
209 this.placeholder = "Type *Markdown* and LaTeX: $\\alpha^2$";
211 IPython.TextCell.apply(this, arguments);
210 IPython.TextCell.apply(this, arguments);
212 this.cell_type = 'markdown';
211 this.cell_type = 'markdown';
213 };
212 };
@@ -245,7 +244,7 b' var IPython = (function (IPython) {'
245 // RSTCell
244 // RSTCell
246
245
247 var RSTCell = function (notebook) {
246 var RSTCell = function (notebook) {
248 this.placeholder = "\u0000Type *ReStructured Text* and LaTeX: $\\alpha^2$";
247 this.placeholder = "Type *ReStructured Text* and LaTeX: $\\alpha^2$";
249 IPython.TextCell.apply(this, arguments);
248 IPython.TextCell.apply(this, arguments);
250 this.cell_type = 'rst';
249 this.cell_type = 'rst';
251 };
250 };
General Comments 0
You need to be logged in to leave comments. Login now