-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Command: afterExecute event (and possibly beforeExecute) #2857
Comments
We'll need both events, and since we decided to make commands the central point of extension (see #340), those events are pretty important. |
While discussing #340 I realised a bug in the current implementation. If the enter feature is loaded after the list feature (and this is possible, because list feature doesn't require the enter feature), then the enter command won't exist during list initialisation, so the specific behaviour won't be injected. This means that we need to fire beforeExecute and afterExecuter on the command collection (which doesn't exist yet, so it must be implemented). This, most likely can be done like this (pseudocode): class CommandCollection extends Collection {
constructor() {
this.on( 'add', ( commandName, item ) => {
item
.delegate( 'beforeExecute', 'afterExecute' )
.to( this, ( evtName ) => `${ commandName }:${ evtName }` );
} );
} Something like this should work, but a feature will need to be added to |
I added this to iteration 4, cause this is kind of a bug. |
In ckeditor/ckeditor5-core#88 we introduced the However, it doesn't solve the Therefore, I consider this issue partially solved and partially invalid. We still need to figure out what to do with the |
This issue is a followup to the discussion we recently had concerning how
Command
s could work and how can we extend them.We came to the conculsion, that it would be useful, if command fired
afterExecute
event which could be listened to by other features that might want to modify results of command execution. This behavior already got implemented inEnterCommand
in https://github.com/ckeditor/ckeditor5-enter/issues/27. However, we would like to see this automated.Requirements:
afterExecute
should be fired withdata
object. Each command can define it's own contents ofdata
object, but every command that modifies model and uses aBatch
instance, should add it indata.batch
. This is needed to add deltas to the same batch so changes done by command and done by custom callback are undone together.afterExecute
should be fired inenqueueChanges
block (if command uses it). This is also to ensure that changes done by command and by custom callback are indistinguishable from user point of view.core.Command
. If the flag istrue
,_doExecute
is wrapped inenqueueChanges
call (this is for 2.). Returned value of_doExecute
is passed toafterExecute
callback (this is for 1.).Other things to keep in mind:
beforeExecute
callback too. Right now there is no use case for such callback but we might want to prepare for it. The problem is that right now theBatch
used by command is instantiated in_doExecute
, so it would be unavailable forbeforeExecute
. We might use flag described in point 3. above to create a batch for command's_doExecute
but pass it tobeforeExecute
callback before_doExecute
is called.beforeExecute
is introduced, we may want to have a way to stop default command behavior. This could be done either by passingdata
object tobeforeExecute
and checking value of, let's say,data.preventDefault
or by adding default command behavior asbeforeExecute
callback withlowest
priority.The text was updated successfully, but these errors were encountered: