Fix cell attachments copy/paste

This commit is contained in:
Julien Rebetez 2016-02-09 15:32:57 +01:00 committed by Julien Rebetez
parent ac9a345400
commit c8266aa507
3 changed files with 23 additions and 12 deletions

View File

@ -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',
};

View File

@ -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();

View File

@ -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;