Fixing auto-indent issues in CodeMirror config.

* Block-level indent/dedent works.
* Tab in docstrings works.
This commit is contained in:
Brian Granger 2012-01-23 19:27:18 -08:00
parent 5947849342
commit d3c3c9e712
2 changed files with 9 additions and 20 deletions

View File

@ -13,6 +13,7 @@ var IPython = (function (IPython) {
var utils = IPython.utils;
var Cell = function (notebook) {
this.placeholder = this.placeholder || '';
this.notebook = notebook;
@ -24,16 +25,17 @@ var IPython = (function (IPython) {
this.element = null;
this.create_element();
if (this.element !== null) {
this.set_autoindent(true);
this.element.data("cell", this);
this.bind_events();
}
this.cell_id = utils.uuid();
};
// Subclasses must implement create_element.
Cell.prototype.create_element = function () {};
Cell.prototype.bind_events = function () {
var that = this;
var nb = that.notebook;
@ -49,6 +51,7 @@ var IPython = (function (IPython) {
});
};
// typeset with MathJax if MathJax is available
Cell.prototype.typeset = function () {
if (window.MathJax){
@ -121,6 +124,7 @@ var IPython = (function (IPython) {
return text;
};
Cell.prototype.grow = function(element) {
// Grow the cell by hand. This is used upon reloading from JSON, when the
// autogrow handler is not called.
@ -138,16 +142,6 @@ var IPython = (function (IPython) {
};
Cell.prototype.set_autoindent = function (state) {
if (state) {
this.code_mirror.setOption('tabMode', 'indent');
this.code_mirror.setOption('enterMode', 'indent');
} else {
this.code_mirror.setOption('tabMode', 'shift');
this.code_mirror.setOption('enterMode', 'flat');
}
};
IPython.Cell = Cell;
return IPython;

View File

@ -32,7 +32,6 @@ var IPython = (function (IPython) {
this.set_tooltipontab(true);
this.set_smartcompleter(true);
this.set_timebeforetooltip(1200);
this.set_autoindent(true);
};
@ -723,6 +722,7 @@ var IPython = (function (IPython) {
};
};
// Cell collapsing and output clearing
Notebook.prototype.collapse = function (index) {
@ -750,22 +750,16 @@ var IPython = (function (IPython) {
this.time_before_tooltip = time;
};
Notebook.prototype.set_tooltipontab = function (state) {
this.tooltip_on_tab = state;
};
Notebook.prototype.set_smartcompleter = function (state) {
this.smart_completer = state;
};
Notebook.prototype.set_autoindent = function (state) {
var cells = this.get_cells();
len = cells.length;
for (var i=0; i<len; i++) {
cells[i].set_autoindent(state);
};
};
Notebook.prototype.clear_all_output = function () {
var ncells = this.ncells();
@ -778,6 +772,7 @@ var IPython = (function (IPython) {
this.dirty = true;
};
// Other cell functions: line numbers, ...
Notebook.prototype.cell_toggle_line_numbers = function() {