diff --git a/src/commands/index.js b/src/commands/index.js index d51cb80a6..e1d533441 100644 --- a/src/commands/index.js +++ b/src/commands/index.js @@ -17,6 +17,8 @@ * * [add](#add) * * [get](#get) * * [has](#has) + * * [run](#run) + * * [stop](#stop) * * @module Commands */ @@ -253,6 +255,40 @@ module.exports = () => { return !!commands[id]; }, + /** + * Execute the command + * @param {String} id Command ID + * @param {Object} [options={}] Options + * @return {*} The return is defined by the command + * @example + * commands.run('myCommand', { someOption: 1 }); + */ + run(id, options = {}) { + let result; + const command = this.get(id); + const editor = em.get('Editor'); + if (command) result = command.callRun(editor, options); + + return result; + }, + + /** + * Stop the command + * @param {String} id Command ID + * @param {Object} [options={}] Options + * @return {*} The return is defined by the command + * @example + * commands.stop('myCommand', { someOption: 1 }); + */ + stop(id, options = {}) { + let result; + const command = this.get(id); + const editor = em.get('Editor'); + if (command) result = command.callStop(editor, options); + + return result; + }, + /** * Load default commands * @return {this}