-
Notifications
You must be signed in to change notification settings - Fork 4
Undo Feature. #1
Conversation
} | ||
} | ||
|
||
this.fire( 'undo', undoBatch ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because redo is also an UndoCommand
the event should be called reverted
. It is strange that redo command fire undo
event.
Beside these small changes mentioned above, two biggest missing parts are: selection handling and UI. If you do not want to handle them as a part of this ticket please create follow-ups. On the other hand selection may change undo so much that there is no point in considering undo without selection. |
Agree... selection is in fact one of the essential things related to undo. |
3f0d5f2
to
66be332
Compare
I've implemented selection handling. It should work really well / perfect with non-selective undo where batches are not divided by other batches or when mixed delta is not conflicting with deltas from undone batch. I did expanded implementation of range transformation so I expect that the selection should work okay in selective undo or mixed conflicting deltas too, but just don't expect wonders. This comment is more suitable for ckeditor5-engine repo because that's where the magic happens, but I wanted to sum up the work here aswell. Changes that are needed for this branch to work are on |
} ); | ||
} ); | ||
|
||
describe( '_doExecute', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should not be tests for private class. If you want to test this method you should change it to "protected".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, what should be done is:
_doExecute
should beprivate
as it is called by_execute
_execute
should be tested.
I'll change it.
…changing to WeakMap.
I added selection direction restoring. I've changed tests so they test I hope it is okay to merge now. |
batch, | ||
{ | ||
ranges: Array.from( this.editor.document.selection.getRanges() ), | ||
isBackward: this.editor.document.selection.isBackward |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still: why now selection.clone()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've already written why in one of comments (it got outdated and hidden). Selection
uses LiveRange
s and would get transformed if we saved Selection
. This, and other reasons.
BTW. which issue is this PR closing? |
#3 |
} ); | ||
|
||
// Whenever batch is reverted by undo command, add it to redo history. | ||
this._undoCommand.listenTo( this._redoCommand, 'revert', ( evt, batch ) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't be the feature listening? In 99% of situation we should be using listenTo()
on this
, because the class which adds a listener is interested in removing it while it's gone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. I probably thought that this solution looks cool but it will be better if feature is listening.
I'm missing some more integrational tests, like:
Those tests should be written with our test utils, so they are easy to read. Having some low level tests is fine, but in a long run they will be hard to maintain, read and extend. That's when the easy-to-write and easy-to-read higher level tests are useful. I'd add some now (in a separate test file most likely) to have easier start in the future and easier review now. |
I could create some integrational tests using model test utils and see if model is fine but right now composer only has I looked at |
Doing changes is one part of a test. Second is setting data and checking the output. Currently you're building a document by creating lots of deltas, then do some operations (or even not – some tests starts with By doing simple: setData( doc, '<p>foo[bar]</p>' );
doc.composer.deleteContents( doc.batch(), doc.selection ); // You can also use some deltas.
expect( getData( doc ) ).to.equal( '<p>foo[]</p>' ); You will be able to quickly generate more test cases which underneath do quite similar things as you did with the low level API. E.g. let's imagine that we find a bug in a very specific case in the future. The first thing to do will be to code a test for it exactly like I showed. So we'll be definitely adding those. I'd just like to have some already, so I can verify on couple of cases that the undo performs as expected. I'm not able to do this quickly based on the existing tests. |
I've added integration tests. Unfortunately, some of them fail, but not directly because of undo algorithms. I've commented them. I will create followup ticket for them in |
I also fixed other issues you pointed out. |
I commented out tests that failed and created followup issue in |
I reported https://github.com/ckeditor/ckeditor5-undo/issues/6 for the ignored tests. |
if ( !batch ) { | ||
batchIndex = this._batchStack.length - 1; | ||
} else { | ||
for ( let i = 0; i < this._batchStack.length; i++ ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could've used: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find. I'll fix it.
http://tests.ckeditor.dev:1030/build/amd/tests/undo/undo#adding%20and%20removing%20content%20multiple%20remove%20and%20undo is failing for me. Could you check? |
…ions. Tests: Fixed the way how feature is initialized and made sure to use beforeEach().
It needed a change in |
Undo Feature. Fixes ckeditor/ckeditor5#2683.