mirror of
https://github.com/jupyter/notebook.git
synced 2025-01-06 11:35:24 +08:00
Updating cell logic.
* Added placeholder to the base Cell class. * Removed the \u0000 char at the beginning of the TextCell placeholder that was there for a CodeMirror bug workaround. * Other refactoring of Cell related Notebook methods.
This commit is contained in:
parent
e1a8835dfa
commit
ccd4de93c7
@ -14,6 +14,7 @@ var IPython = (function (IPython) {
|
||||
var utils = IPython.utils;
|
||||
|
||||
var Cell = function (notebook) {
|
||||
this.placeholder = this.placeholder || '';
|
||||
this.notebook = notebook;
|
||||
this.read_only = false;
|
||||
if (notebook){
|
||||
|
@ -93,6 +93,24 @@ var IPython = (function (IPython) {
|
||||
var cursor = editor.getCursor();
|
||||
var pre_cursor = editor.getRange({line:cursor.line,ch:0},cursor).trim()+'(';
|
||||
that.request_tooltip_after_time(pre_cursor,tooltip_wait_time);
|
||||
} else if (event.which === 38) {
|
||||
// If we are not at the top, let CM handle the up arrow and
|
||||
// prevent the global keydown handler from handling it.
|
||||
if (!that.at_top()) {
|
||||
event.stop();
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
};
|
||||
} else if (event.which === 40) {
|
||||
// If we are not at the bottom, let CM handle the down arrow and
|
||||
// prevent the global keydown handler from handling it.
|
||||
if (!that.at_bottom()) {
|
||||
event.stop();
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
};
|
||||
} else if (event.keyCode === 9 && event.type == 'keydown') {
|
||||
// Tab completion.
|
||||
var cur = editor.getCursor();
|
||||
|
@ -512,8 +512,7 @@ var IPython = (function (IPython) {
|
||||
var i = this.index_or_selected(index);
|
||||
var source_element = this.cell_elements().eq(i);
|
||||
var source_cell = source_element.data("cell");
|
||||
if (source_cell instanceof IPython.HTMLCell ||
|
||||
source_cell instanceof IPython.MarkdownCell) {
|
||||
if (!(source_cell instanceof IPython.CodeCell)) {
|
||||
this.insert_code_cell_below(i);
|
||||
var target_cell = this.cells()[i+1];
|
||||
var text = source_cell.get_text();
|
||||
@ -534,27 +533,23 @@ var IPython = (function (IPython) {
|
||||
var source_element = this.cell_elements().eq(i);
|
||||
var source_cell = source_element.data("cell");
|
||||
var target_cell = null;
|
||||
if (source_cell instanceof IPython.CodeCell) {
|
||||
this.insert_markdown_cell_below(i);
|
||||
target_cell = this.cells()[i+1];
|
||||
var text = source_cell.get_text();
|
||||
} else if (source_cell instanceof IPython.HTMLCell) {
|
||||
if (!(source_cell instanceof IPython.MarkdownCell)) {
|
||||
this.insert_markdown_cell_below(i);
|
||||
target_cell = this.cells()[i+1];
|
||||
var text = source_cell.get_text();
|
||||
if (text === source_cell.placeholder) {
|
||||
text = target_cell.placeholder;
|
||||
};
|
||||
if (target_cell !== null) {
|
||||
if (text === "") {text = target_cell.placeholder;};
|
||||
// The edit must come before the set_text.
|
||||
target_cell.edit();
|
||||
target_cell.set_text(text);
|
||||
source_element.remove();
|
||||
target_cell.select();
|
||||
}
|
||||
}
|
||||
if (target_cell !== null) {
|
||||
if (text === "") {text = target_cell.placeholder;};
|
||||
// The edit must come before the set_text.
|
||||
target_cell.edit();
|
||||
target_cell.set_text(text);
|
||||
source_element.remove();
|
||||
target_cell.select();
|
||||
}
|
||||
this.dirty = true;
|
||||
this.dirty = true;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@ -564,25 +559,23 @@ var IPython = (function (IPython) {
|
||||
var source_element = this.cell_elements().eq(i);
|
||||
var source_cell = source_element.data("cell");
|
||||
var target_cell = null;
|
||||
if (source_cell instanceof IPython.CodeCell) {
|
||||
this.insert_html_cell_below(i);
|
||||
target_cell = this.cells()[i+1];
|
||||
var text = source_cell.get_text();
|
||||
} else if (source_cell instanceof IPython.MarkdownCell) {
|
||||
if (!(source_cell instanceof IPython.HTMLCell)) {
|
||||
this.insert_html_cell_below(i);
|
||||
target_cell = this.cells()[i+1];
|
||||
var text = source_cell.get_text();
|
||||
if (text === source_cell.placeholder) {
|
||||
text = target_cell.placeholder;
|
||||
};
|
||||
if (target_cell !== null) {
|
||||
if (text === "") {text = target_cell.placeholder;};
|
||||
// The edit must come before the set_text.
|
||||
target_cell.edit();
|
||||
target_cell.set_text(text);
|
||||
source_element.remove();
|
||||
target_cell.select();
|
||||
}
|
||||
}
|
||||
if (target_cell !== null) {
|
||||
if (text === "") {text = target_cell.placeholder;};
|
||||
target_cell.set_text(text);
|
||||
source_element.remove();
|
||||
target_cell.edit();
|
||||
}
|
||||
this.dirty = true;
|
||||
this.dirty = true;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@ -629,14 +622,12 @@ var IPython = (function (IPython) {
|
||||
var cell_data = this.clipboard;
|
||||
if (cell_data.cell_type == 'code') {
|
||||
new_cell = this.insert_code_cell_above();
|
||||
new_cell.fromJSON(cell_data);
|
||||
} else if (cell_data.cell_type === 'html') {
|
||||
new_cell = this.insert_html_cell_above();
|
||||
new_cell.fromJSON(cell_data);
|
||||
} else if (cell_data.cell_type === 'markdown') {
|
||||
new_cell = this.insert_markdown_cell_above();
|
||||
new_cell.fromJSON(cell_data);
|
||||
};
|
||||
new_cell.fromJSON(cell_data);
|
||||
this.select_next();
|
||||
this.delete_cell();
|
||||
};
|
||||
@ -648,14 +639,12 @@ var IPython = (function (IPython) {
|
||||
var cell_data = this.clipboard;
|
||||
if (cell_data.cell_type == 'code') {
|
||||
new_cell = this.insert_code_cell_above();
|
||||
new_cell.fromJSON(cell_data);
|
||||
} else if (cell_data.cell_type === 'html') {
|
||||
new_cell = this.insert_html_cell_above();
|
||||
new_cell.fromJSON(cell_data);
|
||||
} else if (cell_data.cell_type === 'markdown') {
|
||||
new_cell = this.insert_markdown_cell_above();
|
||||
new_cell.fromJSON(cell_data);
|
||||
};
|
||||
new_cell.fromJSON(cell_data);
|
||||
};
|
||||
};
|
||||
|
||||
@ -665,14 +654,12 @@ var IPython = (function (IPython) {
|
||||
var cell_data = this.clipboard;
|
||||
if (cell_data.cell_type == 'code') {
|
||||
new_cell = this.insert_code_cell_below();
|
||||
new_cell.fromJSON(cell_data);
|
||||
} else if (cell_data.cell_type === 'html') {
|
||||
new_cell = this.insert_html_cell_below();
|
||||
new_cell.fromJSON(cell_data);
|
||||
} else if (cell_data.cell_type === 'markdown') {
|
||||
new_cell = this.insert_markdown_cell_below();
|
||||
new_cell.fromJSON(cell_data);
|
||||
};
|
||||
new_cell.fromJSON(cell_data);
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -15,7 +15,6 @@ var IPython = (function (IPython) {
|
||||
|
||||
var TextCell = function (notebook) {
|
||||
this.code_mirror_mode = this.code_mirror_mode || 'htmlmixed';
|
||||
this.placeholder = this.placeholder || '\u0000';
|
||||
IPython.Cell.apply(this, arguments);
|
||||
this.rendered = false;
|
||||
this.cell_type = this.cell_type || 'text';
|
||||
@ -182,7 +181,7 @@ var IPython = (function (IPython) {
|
||||
// HTMLCell
|
||||
|
||||
var HTMLCell = function (notebook) {
|
||||
this.placeholder = "\u0000Type <strong>HTML</strong> and LaTeX: $\\alpha^2$";
|
||||
this.placeholder = "Type <strong>HTML</strong> and LaTeX: $\\alpha^2$";
|
||||
IPython.TextCell.apply(this, arguments);
|
||||
this.cell_type = 'html';
|
||||
};
|
||||
@ -207,7 +206,7 @@ var IPython = (function (IPython) {
|
||||
// MarkdownCell
|
||||
|
||||
var MarkdownCell = function (notebook) {
|
||||
this.placeholder = "\u0000Type *Markdown* and LaTeX: $\\alpha^2$";
|
||||
this.placeholder = "Type *Markdown* and LaTeX: $\\alpha^2$";
|
||||
IPython.TextCell.apply(this, arguments);
|
||||
this.cell_type = 'markdown';
|
||||
};
|
||||
@ -245,7 +244,7 @@ var IPython = (function (IPython) {
|
||||
// RSTCell
|
||||
|
||||
var RSTCell = function (notebook) {
|
||||
this.placeholder = "\u0000Type *ReStructured Text* and LaTeX: $\\alpha^2$";
|
||||
this.placeholder = "Type *ReStructured Text* and LaTeX: $\\alpha^2$";
|
||||
IPython.TextCell.apply(this, arguments);
|
||||
this.cell_type = 'rst';
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user