Skip to content

Commit

Permalink
Fixing selection and focus logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
ellisonbg committed Jul 21, 2011
1 parent 9e95afe commit 04da04e
Showing 1 changed file with 43 additions and 12 deletions.
55 changes: 43 additions & 12 deletions IPython/frontend/html/notebook/static/js/notebook.js
Expand Up @@ -16,14 +16,15 @@ var Notebook = function (selector) {


Notebook.prototype.bind_events = function () { Notebook.prototype.bind_events = function () {
var that = this; var that = this;
that.element.keydown(function (event) { $(document).keydown(function (event) {
console.log(event); console.log(event);
if (event.which == 38 && event.shiftKey) { if (event.which == 38 && event.shiftKey) {
that.select_prev(); that.select_prev();
} else if (event.which == 40 && event.shiftKey) { } else if (event.which == 40 && event.shiftKey) {
that.select_next(); that.select_next();
} else if (event.which == 13 && event.shiftKey) { } else if (event.which == 13 && event.shiftKey) {
// The focus is not quite working here. // The focus is not quite working here.
event.preventDefault();
that.insert_code_cell_after(); that.insert_code_cell_after();
} }
}); });
Expand Down Expand Up @@ -155,7 +156,7 @@ Notebook.prototype.insert_cell_before = function (cell, index) {
this.append_cell(cell); this.append_cell(cell);
return this; return this;
}; };
if (index > 0 && index < ncells) { if (index >= 0 && index < ncells) {
this.cell_elements().eq(index).before(cell.element); this.cell_elements().eq(index).before(cell.element);
}; };
return this; return this;
Expand All @@ -170,6 +171,7 @@ Notebook.prototype.move_cell_up = function (index) {
if (pivot !== null && tomove !== null) { if (pivot !== null && tomove !== null) {
tomove.detach(); tomove.detach();
pivot.before(tomove); pivot.before(tomove);
this.select(i-1);
}; };
}; };
return this; return this;
Expand All @@ -184,6 +186,7 @@ Notebook.prototype.move_cell_down = function (index) {
if (pivot !== null && tomove !== null) { if (pivot !== null && tomove !== null) {
tomove.detach(); tomove.detach();
pivot.after(tomove); pivot.after(tomove);
this.select(i+1);
}; };
}; };
return this; return this;
Expand Down Expand Up @@ -321,7 +324,10 @@ var Cell = function (notebook) {
Cell.prototype.select = function () { Cell.prototype.select = function () {
this.element.addClass('ui-widget-content ui-corner-all'); this.element.addClass('ui-widget-content ui-corner-all');
this.selected = true; this.selected = true;
// TODO: we need t test across browsers to see if both of these are needed.
// In the meantime, there should not be any harm in having them both.
this.element.find('textarea').trigger('focusin'); this.element.find('textarea').trigger('focusin');
this.element.find('textarea').trigger('focus');
}; };




Expand Down Expand Up @@ -445,27 +451,52 @@ TextCell.prototype.create_element = function () {
}; };




TextCell.prototype.config_mathjax = function () { TextCell.prototype.select = function () {
this.edit();
Cell.prototype.select.apply(this);
};


TextCell.prototype.edit = function () {
var text_cell = this.element; var text_cell = this.element;
var input = text_cell.find("textarea.text_cell_input"); var input = text_cell.find("textarea.text_cell_input");
var output = text_cell.find("div.text_cell_render"); var output = text_cell.find("div.text_cell_render");
output.hide();
input.show().trigger('focus');
};



TextCell.prototype.render = function () {
var text_cell = this.element;
var input = text_cell.find("textarea.text_cell_input");
var output = text_cell.find("div.text_cell_render");
var text = input.val();
output.html(text)
input.html(text);
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
input.hide();
output.show();
};


TextCell.prototype.config_mathjax = function () {
var text_cell = this.element;
var that = this;
text_cell.click(function () { text_cell.click(function () {
output.hide(); that.edit();
input.show().trigger('focus');
}).focusout(function () { }).focusout(function () {
var text = input.val(); that.render();
output.html(text)
input.html(text);
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
input.hide();
output.show();
}); });


text_cell.trigger("focusout"); text_cell.trigger("focusout");
}; };




//============================================================================
// On document ready
//============================================================================


$(document).ready(function () { $(document).ready(function () {


MathJax.Hub.Config({ MathJax.Hub.Config({
Expand Down

0 comments on commit 04da04e

Please sign in to comment.