Skip to content
This repository

fix for #1678, undo no longer clears cells #1965

Merged
merged 1 commit into from almost 2 years ago

2 participants

Paul Ivanov Min RK
Paul Ivanov
Collaborator
ivanov commented June 14, 2012

With these changes, Ctrl-Z inside of codemirror cells will only undo up to the text that was in the cell when it was loaded from JSON. This fixes #1678.

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 to whatever it was at the time of the cell type switch.

For example, if a cell had contents changed from X -> Y -> Z, and then you change the cell type, before this commit, its history becomes Ø -> Z (where Ø is just empty), so pressing Ctrl-Z once in a changed cell just erases all of it's contents. After this commit, the new cell's history just gets reset to Z

Paul Ivanov 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
221ff6a
Min RK
Owner
minrk commented June 14, 2012

What's the difference between losing and resetting the history?

Paul Ivanov
Collaborator
ivanov commented June 14, 2012

In the notebook, when a CodeMirror cell is initiated, it's text value is set to a blank. Later, the cell value gets set with set_text(text) - which causes that to be an entry in the cell's history, and so the undo history's initial entry is that of a blank value. So resetting the history after a call to set_text causes the initial entry to become whatever it was in the JSON.

Min RK
Owner
minrk commented June 14, 2012

ok, thanks.

Paul Ivanov
Collaborator
ivanov commented June 14, 2012

sorry about the confusing wording, if a cell had contents changed from X -> Y -> Z, and then you change the cell type, before this commit, its history becomes Ø -> Z (where Ø is just empty), so pressing Ctrl-Z once in a changed cell just erases all of it's contents. After this commit, the new cell's history just gets reset to Z

Min RK
Owner
minrk commented June 15, 2012

Is there any case where calling 'set_text' shouldn't do this? I'm wondering if that's where this call belongs.

Min RK
Owner
minrk commented June 15, 2012

If that's not true, then I'm fine merging as-is, and we can worry about consolidation later.

Paul Ivanov
Collaborator
ivanov commented June 15, 2012

Is there any case where calling 'set_text' shouldn't do this?

yes. Merging or splitting a cell also uses set_text. So if you do a split, and then change your mind, you can actually undo back within both cells and one of them will return to the unified pre-split stage, and the other will return to empty state.

%load and %loadpy magics also ends up using set_text - and since those create new cells, and all new cells created within a session have Ø at the root of their history, not resetting the history keeps things consistent.

I can also imagine downstream widgets using this function, the effects of which would then be undo-able

Min RK
Owner
minrk commented June 15, 2012

gotcha, merging as-is then.

Min RK minrk merged commit 172b680 into from June 15, 2012
Min RK minrk closed this June 15, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jun 14, 2012
Paul Ivanov 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
221ff6a
This page is out of date. Refresh to see the latest.
3  IPython/frontend/html/notebook/static/js/codecell.js
@@ -267,6 +267,9 @@ var IPython = (function (IPython) {
267 267
         if (data.cell_type === 'code') {
268 268
             if (data.input !== undefined) {
269 269
                 this.set_text(data.input);
  270
+                // make this value the starting point, so that we can only undo
  271
+                // to this state, instead of a blank cell
  272
+                this.code_mirror.clearHistory();
270 273
             }
271 274
             if (data.prompt_number !== undefined) {
272 275
                 this.set_input_prompt(data.prompt_number);
15  IPython/frontend/html/notebook/static/js/notebook.js
@@ -602,6 +602,9 @@ var IPython = (function (IPython) {
602 602
                     text = '';
603 603
                 }
604 604
                 target_cell.set_text(text);
  605
+                // make this value the starting point, so that we can only undo
  606
+                // to this state, instead of a blank cell
  607
+                target_cell.code_mirror.clearHistory();
605 608
                 source_element.remove();
606 609
                 this.dirty = true;
607 610
             };
@@ -623,6 +626,9 @@ var IPython = (function (IPython) {
623 626
                 // The edit must come before the set_text.
624 627
                 target_cell.edit();
625 628
                 target_cell.set_text(text);
  629
+                // make this value the starting point, so that we can only undo
  630
+                // to this state, instead of a blank cell
  631
+                target_cell.code_mirror.clearHistory();
626 632
                 source_element.remove();
627 633
                 this.dirty = true;
628 634
             };
@@ -645,6 +651,9 @@ var IPython = (function (IPython) {
645 651
                 // The edit must come before the set_text.
646 652
                 target_cell.edit();
647 653
                 target_cell.set_text(text);
  654
+                // make this value the starting point, so that we can only undo
  655
+                // to this state, instead of a blank cell
  656
+                target_cell.code_mirror.clearHistory();
648 657
                 source_element.remove();
649 658
                 this.dirty = true;
650 659
             };
@@ -667,6 +676,9 @@ var IPython = (function (IPython) {
667 676
                 // The edit must come before the set_text.
668 677
                 target_cell.edit();
669 678
                 target_cell.set_text(text);
  679
+                // make this value the starting point, so that we can only undo
  680
+                // to this state, instead of a blank cell
  681
+                target_cell.code_mirror.clearHistory();
670 682
                 source_element.remove();
671 683
                 this.dirty = true;
672 684
             };
@@ -693,6 +705,9 @@ var IPython = (function (IPython) {
693 705
                 target_cell.set_level(level);
694 706
                 target_cell.edit();
695 707
                 target_cell.set_text(text);
  708
+                // make this value the starting point, so that we can only undo
  709
+                // to this state, instead of a blank cell
  710
+                target_cell.code_mirror.clearHistory();
696 711
                 source_element.remove();
697 712
                 this.dirty = true;
698 713
             };
3  IPython/frontend/html/notebook/static/js/textcell.js
@@ -158,6 +158,9 @@ var IPython = (function (IPython) {
158 158
         if (data.cell_type === this.cell_type) {
159 159
             if (data.source !== undefined) {
160 160
                 this.set_text(data.source);
  161
+                // make this value the starting point, so that we can only undo
  162
+                // to this state, instead of a blank cell
  163
+                this.code_mirror.clearHistory();
161 164
                 this.set_rendered(data.rendered || '');
162 165
                 this.rendered = false;
163 166
                 this.render();
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.