diff --git a/IPython/html/static/notebook/js/cell.js b/IPython/html/static/notebook/js/cell.js
index e695b3e..d764ab7 100644
--- a/IPython/html/static/notebook/js/cell.js
+++ b/IPython/html/static/notebook/js/cell.js
@@ -385,7 +385,8 @@ define([
**/
Cell.prototype.toJSON = function () {
var data = {};
- data.metadata = this.metadata;
+ // deepcopy the metadata so copied cells don't share the same object
+ data.metadata = JSON.parse(JSON.stringify(this.metadata));
data.cell_type = this.cell_type;
return data;
};
@@ -404,22 +405,32 @@ define([
/**
- * can the cell be split into two cells
+ * can the cell be split into two cells (false if not deletable)
* @method is_splittable
**/
Cell.prototype.is_splittable = function () {
- return true;
+ return this.is_deletable();
};
/**
- * can the cell be merged with other cells
+ * can the cell be merged with other cells (false if not deletable)
* @method is_mergeable
**/
Cell.prototype.is_mergeable = function () {
- return true;
+ return this.is_deletable();
};
+ /**
+ * is the cell deletable? (true by default)
+ * @method is_deletable
+ **/
+ Cell.prototype.is_deletable = function () {
+ if (this.metadata.deletable === undefined) {
+ return true;
+ }
+ return Boolean(this.metadata.deletable);
+ };
/**
* @return {String} - the text before the cursor
diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js
index ac8b220..4235774 100644
--- a/IPython/html/static/notebook/js/notebook.js
+++ b/IPython/html/static/notebook/js/notebook.js
@@ -765,7 +765,11 @@ define([
*/
Notebook.prototype.delete_cell = function (index) {
var i = this.index_or_selected(index);
- var cell = this.get_selected_cell();
+ var cell = this.get_cell(i);
+ if (!cell.is_deletable()) {
+ return this;
+ }
+
this.undelete_backup = cell.toJSON();
$('#undelete_cell').removeClass('disabled');
if (this.is_valid_cell_index(i)) {
@@ -1193,6 +1197,10 @@ define([
Notebook.prototype.copy_cell = function () {
var cell = this.get_selected_cell();
this.clipboard = cell.toJSON();
+ // remove undeletable status from the copied cell
+ if (this.clipboard.metadata.deletable !== undefined) {
+ delete this.clipboard.metadata.deletable;
+ }
this.enable_paste();
};