diff --git a/notebook/static/notebook/js/menubar.js b/notebook/static/notebook/js/menubar.js index 94912c943..04984803a 100644 --- a/notebook/static/notebook/js/menubar.js +++ b/notebook/static/notebook/js/menubar.js @@ -228,6 +228,9 @@ define([ '#toggle_all_output': 'toggle-all-cells-output-collapsed', '#toggle_all_output_scroll': 'toggle-all-cells-output-scrolled', '#clear_all_output': 'clear-all-cells-output', + '#cut_cell_attachments': 'cut-cell-attachments', + '#copy_cell_attachments': 'copy-cell-attachments', + '#paste_cell_attachments': 'paste-cell-attachments', '#insert_image': 'insert-image', }; diff --git a/notebook/static/notebook/js/notebook.js b/notebook/static/notebook/js/notebook.js index a77de79de..78bda1740 100644 --- a/notebook/static/notebook/js/notebook.js +++ b/notebook/static/notebook/js/notebook.js @@ -126,6 +126,7 @@ define(function (require) { this.kernel = null; this.kernel_busy = false; this.clipboard = null; + this.clipboard_attachments = null; this.undelete_backup_stack = []; this.paste_enabled = false; this.paste_attachments_enabled = false; @@ -1709,11 +1710,13 @@ define(function (require) { */ Notebook.prototype.cut_cell_attachments = function() { var cell = this.get_selected_cell(); - this.clipboard_attachments = cell.attachments; - this.enable_attachments_paste(); - cell.attachments = {}; - cell.unrender(); - cell.render(); + if (cell.attachments !== undefined) { + this.clipboard_attachments = cell.attachments; + this.enable_attachments_paste(); + delete cell.attachments; + cell.unrender(); + cell.render(); + } }; /** @@ -1721,12 +1724,13 @@ define(function (require) { */ Notebook.prototype.copy_cell_attachments = function() { var cell = this.get_selected_cell(); - // Do a deep copy of attachments to avoid subsequent modification - // to the cell to modify the clipboard - this.clipboard_attachments = $.extend(true, {}, cell.attachments); - this.enable_attachments_paste(); - cell.unrender(); - cell.render(); + if (cell.attachments !== undefined) { + // Do a deep copy of attachments to avoid subsequent modification + // to the cell to modify the clipboard + console.log(cell.attachments); + this.clipboard_attachments = $.extend(true, {}, cell.attachments); + this.enable_attachments_paste(); + } }; /** @@ -1737,6 +1741,9 @@ define(function (require) { if (this.clipboard_attachments !== null && this.paste_attachments_enabled) { var cell = this.get_selected_cell(); + if (cell.attachments === undefined) { + cell.attachments = {}; + } $.extend(cell.attachments, this.clipboard_attachments); cell.unrender(); cell.render(); diff --git a/notebook/static/notebook/js/textcell.js b/notebook/static/notebook/js/textcell.js index 104a54e98..780923b73 100644 --- a/notebook/static/notebook/js/textcell.js +++ b/notebook/static/notebook/js/textcell.js @@ -215,7 +215,8 @@ define([ } // Deepcopy the attachments so copied cells don't share the same // objects - if (this.attachments !== undefined) { + if (this.attachments !== undefined + && Object.keys(this.attachments).length > 0) { data.attachments = JSON.parse(JSON.stringify(this.attachments)); } return data;