refactor to improve cell switching in edit mode

This code was repeated in both CodeCell and TextCell, both of which are
extensions of Cell, so this just unifies the logic in Cell.

TextCell had logic here to check if the cell was rendered or not, but I
don't believe it is possible to end up triggering such a code path.
(Should that be required, I can always just add back these methods to
TextCell, performing the .rendered==True check, and calling the Cell

prior to this, code mirror at_top would only return true on if the
cursor was at the first character of the top line. Now, pressing up
arrow on any character on the top line will take you to the cell above.

The same applies for the bottom line. Pressing down arrow would only go
to the next cell if the cursor was at a location *after* the last
character (something that is only possible to achieve in vim mode if the
last line is empty, for example). Now, down arrow on any character of
the last line will go to the next cell.
Paul Ivanov 12 years ago
parent 8889a7581c
commit 71d4c427c9

@ -229,6 +229,34 @@ var IPython = (function (IPython) {
}
};
/**
* @method at_top
* @return {Boolean}
*/
Cell.prototype.at_top = function () {
var cm = this.code_mirror
var cursor = cm.getCursor();
if (cursor.line === 0 && cm.findPosV(cursor, -1, 'line').hitSide) {
console.log('at top');
return true;
} else {
return false;
}
};
/**
* @method at_bottom
* @return {Boolean}
* */
Cell.prototype.at_bottom = function () {
var cm = this.code_mirror
var cursor = cm.getCursor();
if (cursor.line === (cm.lineCount()-1) && cm.findPosV(cursor, 1, 'line').hitSide) {
return true;
} else {
return false;
}
};
/**
* enter the command mode for the cell
* @method command_mode

@ -501,26 +501,6 @@ var IPython = (function (IPython) {
};
CodeCell.prototype.at_top = function () {
var cursor = this.code_mirror.getCursor();
if (cursor.line === 0 && cursor.ch === 0) {
return true;
} else {
return false;
}
};
CodeCell.prototype.at_bottom = function () {
var cursor = this.code_mirror.getCursor();
if (cursor.line === (this.code_mirror.lineCount()-1) && cursor.ch === this.code_mirror.getLine(cursor.line).length) {
return true;
} else {
return false;
}
};
CodeCell.prototype.clear_output = function (wait) {
this.output_area.clear_output(wait);
this.set_input_prompt();

@ -242,40 +242,6 @@ var IPython = (function (IPython) {
this.element.find('div.text_cell_render').html(text);
};
/**
* @method at_top
* @return {Boolean}
*/
TextCell.prototype.at_top = function () {
if (this.rendered) {
return true;
} else {
var cursor = this.code_mirror.getCursor();
if (cursor.line === 0 && cm.findPosV(cm.getCursor(), -1, 'line', cm.charCoords(cm.getCursor(),'div').left).hitSide) {
console.log('at top');
return true;
} else {
return false;
}
}
};
/**
* @method at_bottom
* @return {Boolean}
* */
TextCell.prototype.at_bottom = function () {
if (this.rendered) {
return true;
} else {
var cursor = this.code_mirror.getCursor();
if (cursor.line === (this.code_mirror.lineCount()-1) && cursor.ch === this.code_mirror.getLine(cursor.line).length) {
return true;
} else {
return false;
}
}
};
/**
* Create Text cell from JSON

Loading…
Cancel
Save