Permalink
Browse files

Cells call grow by hand when they reload from JSON.

  • Loading branch information...
1 parent 9447eb0 commit a563b92ea9067a40deddfeb4326918e9033a1fcf @ellisonbg ellisonbg committed with ellisonbg May 3, 2011
Showing with 20 additions and 0 deletions.
  1. +20 −0 IPython/frontend/html/notebook/static/js/notebook.js
@@ -580,6 +580,23 @@ var Cell = function (notebook) {
};
+Cell.prototype.grow = function(element) {
+ // Grow the cell by hand. This is used upon reloading from JSON, when the
+ // autogrow handler is not called.
+ var dom = element.get(0);
+ var lines_count = 0;
+ // modified split rule from
+ // http://stackoverflow.com/questions/2035910/how-to-get-the-number-of-lines-in-a-textarea/2036424#2036424
+ var lines = dom.value.split(/\r|\r\n|\n/);
+ lines_count = lines.length;
+ if (lines_count >= 1) {
+ dom.rows = lines_count;
+ } else {
+ dom.rows = 1;
+ }
+};
+
+
Cell.prototype.select = function () {
this.element.addClass('ui-widget-content ui-corner-all');
this.selected = true;
@@ -658,6 +675,7 @@ CodeCell.prototype.append_pyout = function (data, n) {
};
};
+
CodeCell.prototype.append_pyerr = function (ename, evalue, tb) {
var s = '';
var len = tb.length;
@@ -752,6 +770,7 @@ CodeCell.prototype.fromJSON = function (data) {
if (data.cell_type === 'code') {
this.set_code(data.code);
this.set_input_prompt(data.prompt_number);
+ this.grow(this.element.find("textarea.input_textarea"));
};
};
@@ -853,6 +872,7 @@ TextCell.prototype.set_text = function(text) {
TextCell.prototype.fromJSON = function (data) {
if (data.cell_type === 'text') {
this.set_text(data.text);
+ this.grow(this.element.find("textarea.text_cell_input"));
};
}

0 comments on commit a563b92

Please sign in to comment.