This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3c348a6
Undo Feature initial commit.
scofalik 4420f98
Changes according to changes in CKE5-core.
scofalik 9eff507
Added: undo.UndoCommand selection restoring + docs update.
scofalik f89097a
Tests, docs: undo.UndoFeature minor tweaks.
scofalik 322c80e
Fixes: UndoFeature/UndoCommand changes Map/Set to WeakMap/WeakSet.
scofalik 2eda14d
Changed: UndoCommand now restores selection direction. + fixes after …
scofalik 82645d6
Changed: Multiple changes in Undo after review.
scofalik 36484d6
Changed: removing commented code + docs.
scofalik 3a5542e
Changed: Fixes after review.
scofalik 89885e9
Tests: Commented out tests that fail.
scofalik bdf3ba9
Renamed _batchStack to more correct _items and made minor simplificat…
Reinmar 859f639
Minor API docs corrections.
Reinmar fdc695a
Minor improvement.
Reinmar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,15 +37,20 @@ export default class UndoCommand extends Command { | |
}; | ||
|
||
this._batchStack.push( { batch, selection } ); | ||
this.refreshState(); | ||
} | ||
|
||
/** | ||
* Removes all batches from the stack. | ||
*/ | ||
clearStack() { | ||
this._batchStack = []; | ||
this.refreshState(); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
_checkEnabled() { | ||
return this._batchStack.length > 0; | ||
} | ||
|
@@ -54,13 +59,26 @@ export default class UndoCommand extends Command { | |
* Executes the command: reverts a {@link engine.treeModel.Batch batch} added to the command's stack, | ||
* applies it on the document and removes the batch from the stack. | ||
* | ||
* @private | ||
* @protected | ||
* @fires undo.undoCommand#event:revert | ||
* @param {Number} [batchIndex] If set, batch under the given index on the stack will be reverted and removed. | ||
* If not set, or invalid, the last added batch will be reverted and removed. | ||
* @param {engine.treeModel.Batch} [batch] If set, batch that should be undone. If that batch is not on undo stack, | ||
* the command execution won't do anything. If not set, the last added batch will be undone. | ||
*/ | ||
_doExecute( batchIndex ) { | ||
batchIndex = this._batchStack[ batchIndex ] ? batchIndex : this._batchStack.length - 1; | ||
_doExecute( batch = null ) { | ||
let batchIndex; | ||
|
||
// If batch is not given, set `batchIndex` to the last index in command stack. | ||
// If it is given, find it on the stack. | ||
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 commentThe 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. |
||
if ( this._batchStack[ i ].batch == batch ) { | ||
batchIndex = i; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
const undoItem = this._batchStack.splice( batchIndex, 1 )[ 0 ]; | ||
|
||
|
@@ -90,7 +108,7 @@ export default class UndoCommand extends Command { | |
|
||
// The ranges will be transformed by deltas from history that took place | ||
// after the selection got stored. | ||
const deltas = this.editor.document.history.getDeltas( undoBatch.deltas[ 0 ].baseVersion ) || []; | ||
const deltas = this.editor.document.history.getDeltas( undoBatch.deltas[ 0 ].baseVersion ); | ||
|
||
// This will keep the transformed ranges. | ||
const transformedRanges = []; | ||
|
@@ -183,6 +201,7 @@ export default class UndoCommand extends Command { | |
this.editor.document.selection.setRanges( transformedRanges, selectionState.isBackward ); | ||
} | ||
|
||
this.refreshState(); | ||
this.fire( 'revert', undoBatch ); | ||
} | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Misses docs.
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.
Oops, it's inherited from
Command
. Hmm... so maybe, to avoid confusion, we could use@inheritDoc
in such cases. Then it will be clear that the doc comes from the parent.