From 01a3053270b8b68c61091b4eb3445e2450b061f6 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Thu, 21 Mar 2019 23:28:13 +0100 Subject: [PATCH] Add `strict` option in Command module configs #1881 --- src/commands/config/config.js | 4 ++++ src/commands/index.js | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/commands/config/config.js b/src/commands/config/config.js index 7d12db6eb..3783fe6b0 100644 --- a/src/commands/config/config.js +++ b/src/commands/config/config.js @@ -5,6 +5,10 @@ module.exports = { defaults: [], + // If true, stateful commands (with `run` and `stop` methods) can't be runned multiple times. + // So, if the command is already active, running it again will not execute the `run` method + strict: 1, + // Editor model // @deprecated em: null, diff --git a/src/commands/index.js b/src/commands/index.js index bee7c7bc1..b4d14fcf1 100644 --- a/src/commands/index.js +++ b/src/commands/index.js @@ -330,7 +330,7 @@ module.exports = () => { const id = command.id; const editor = em.get('Editor'); - if (!this.isActive(id) || options.force) { + if (!this.isActive(id) || options.force || !c.strict) { if (id && command.stop && !command.noStop) { active[id] = result; } @@ -355,7 +355,7 @@ module.exports = () => { const id = command.id; const editor = em.get('Editor'); - if (this.isActive(id) || options.force) { + if (this.isActive(id) || options.force || !c.strict) { if (id) delete active[id]; result = command.callStop(editor, options); }