From ad07d0cf445a163f323af7f3922841fc3e20a4fa Mon Sep 17 00:00:00 2001 From: Paul Ivanov Date: Thu, 14 Jun 2012 17:36:34 -0700 Subject: [PATCH] fix for #1678, undo no longer clears cells I found another bug where switching the cell type causes the loss of all undo history for that cell. With this commit, switching the cell type simply resets the history --- .../frontend/html/notebook/static/js/codecell.js | 3 +++ .../frontend/html/notebook/static/js/notebook.js | 15 +++++++++++++++ .../frontend/html/notebook/static/js/textcell.js | 3 +++ 3 files changed, 21 insertions(+) diff --git a/IPython/frontend/html/notebook/static/js/codecell.js b/IPython/frontend/html/notebook/static/js/codecell.js index 275493746..41e7156ed 100644 --- a/IPython/frontend/html/notebook/static/js/codecell.js +++ b/IPython/frontend/html/notebook/static/js/codecell.js @@ -267,6 +267,9 @@ var IPython = (function (IPython) { if (data.cell_type === 'code') { if (data.input !== undefined) { this.set_text(data.input); + // make this value the starting point, so that we can only undo + // to this state, instead of a blank cell + this.code_mirror.clearHistory(); } if (data.prompt_number !== undefined) { this.set_input_prompt(data.prompt_number); diff --git a/IPython/frontend/html/notebook/static/js/notebook.js b/IPython/frontend/html/notebook/static/js/notebook.js index ef44f7816..12268e9a7 100644 --- a/IPython/frontend/html/notebook/static/js/notebook.js +++ b/IPython/frontend/html/notebook/static/js/notebook.js @@ -602,6 +602,9 @@ var IPython = (function (IPython) { text = ''; } target_cell.set_text(text); + // make this value the starting point, so that we can only undo + // to this state, instead of a blank cell + target_cell.code_mirror.clearHistory(); source_element.remove(); this.dirty = true; }; @@ -623,6 +626,9 @@ var IPython = (function (IPython) { // The edit must come before the set_text. target_cell.edit(); target_cell.set_text(text); + // make this value the starting point, so that we can only undo + // to this state, instead of a blank cell + target_cell.code_mirror.clearHistory(); source_element.remove(); this.dirty = true; }; @@ -645,6 +651,9 @@ var IPython = (function (IPython) { // The edit must come before the set_text. target_cell.edit(); target_cell.set_text(text); + // make this value the starting point, so that we can only undo + // to this state, instead of a blank cell + target_cell.code_mirror.clearHistory(); source_element.remove(); this.dirty = true; }; @@ -667,6 +676,9 @@ var IPython = (function (IPython) { // The edit must come before the set_text. target_cell.edit(); target_cell.set_text(text); + // make this value the starting point, so that we can only undo + // to this state, instead of a blank cell + target_cell.code_mirror.clearHistory(); source_element.remove(); this.dirty = true; }; @@ -693,6 +705,9 @@ var IPython = (function (IPython) { target_cell.set_level(level); target_cell.edit(); target_cell.set_text(text); + // make this value the starting point, so that we can only undo + // to this state, instead of a blank cell + target_cell.code_mirror.clearHistory(); source_element.remove(); this.dirty = true; }; diff --git a/IPython/frontend/html/notebook/static/js/textcell.js b/IPython/frontend/html/notebook/static/js/textcell.js index 38b302e16..2e52a7538 100644 --- a/IPython/frontend/html/notebook/static/js/textcell.js +++ b/IPython/frontend/html/notebook/static/js/textcell.js @@ -158,6 +158,9 @@ var IPython = (function (IPython) { if (data.cell_type === this.cell_type) { if (data.source !== undefined) { this.set_text(data.source); + // make this value the starting point, so that we can only undo + // to this state, instead of a blank cell + this.code_mirror.clearHistory(); this.set_rendered(data.rendered || ''); this.rendered = false; this.render();