Browse Source

Update commands events

pull/5796/head
Artur Arseniev 2 years ago
parent
commit
c47ed84a0b
  1. 16
      docs/modules/Commands.md

16
docs/modules/Commands.md

@ -267,20 +267,20 @@ The Commands module offers also a set of events that you can use to intercept th
By using our previously created `my-command-modal` command let's see which events we can listen to By using our previously created `my-command-modal` command let's see which events we can listen to
```js ```js
editor.on('run:my-command-modal', () => { editor.on('command:run:my-command-modal', () => {
console.log('After `my-command-modal` execution'); console.log('After `my-command-modal` execution');
// For example, you can add extra content to the modal // For example, you can add extra content to the modal
const modalContent = editor.Modal.getContentEl(); const modalContent = editor.Modal.getContentEl();
modalContent.insertAdjacentHTML('beforeEnd', '<div>Some content</div>'); modalContent.insertAdjacentHTML('beforeEnd', '<div>Some content</div>');
}); });
editor.on('run:my-command-modal:before', () => { editor.on('command:run:before:my-command-modal', () => {
console.log('Before `my-command-modal` execution'); console.log('Before `my-command-modal` execution');
}); });
// for stateful commands // for stateful commands
editor.on('stop:my-command-modal', () => { editor.on('command:stop:my-command-modal', () => {
console.log('After `my-command-modal` is stopped'); console.log('After `my-command-modal` is stopped');
}); });
editor.on('stop:my-command-modal:before', () => { editor.on('command:stop:before:my-command-modal:before', () => {
console.log('Before `my-command-modal` is stopped'); console.log('Before `my-command-modal` is stopped');
}); });
``` ```
@ -288,11 +288,11 @@ editor.on('stop:my-command-modal:before', () => {
If you need, you can also listen to all commands If you need, you can also listen to all commands
```js ```js
editor.on('run', commandId => { editor.on('command:run', commandId => {
console.log('Run', commandId); console.log('Run', commandId);
}); });
editor.on('stop', commandId => { editor.on('command:stop', commandId => {
console.log('Stop', commandId); console.log('Stop', commandId);
}); });
``` ```
@ -300,12 +300,12 @@ editor.on('stop', commandId => {
### Interrupt command flow ### Interrupt command flow
Sometimes you might need to interrupt the execution of an existant command due to some condition. In that case, you have to use `run:{COMMAND-ID}:before` event and set to `true` the abort option Sometimes you might need to interrupt the execution of an existant command due to some condition. In that case, you have to use `command:run:before:{COMMAND-ID}` event and set to `true` the abort option
```js ```js
const condition = 1; const condition = 1;
editor.on('run:my-command-modal:before', options => { editor.on('command:run:before:my-command-modal', options => {
if (condition) { if (condition) {
options.abort = true; options.abort = true;
console.log('Prevent `my-command-modal` from execution'); console.log('Prevent `my-command-modal` from execution');

Loading…
Cancel
Save