From 2c9c550bb1458b7f348bd59dcc5fd8831abc8d7a Mon Sep 17 00:00:00 2001 From: artf Date: Fri, 30 Nov 2018 17:12:04 +0100 Subject: [PATCH] Improve isInputFocused method in Canvas --- src/canvas/config/config.js | 9 ++++++++- src/canvas/index.js | 10 +++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/canvas/config/config.js b/src/canvas/config/config.js index 1cd99480a..3c8c2a3b6 100644 --- a/src/canvas/config/config.js +++ b/src/canvas/config/config.js @@ -24,5 +24,12 @@ module.exports = { * return component.getName(); * } */ - customBadgeLabel: '' + customBadgeLabel: '', + + /** + * When some textable component is selected and focused (eg. input or text component) the editor + * stops some commands (eg. disables the copy/paste of components with CTRL+C/V to allow the copy/paste of the text). + * This option allows to customize, by a selector, which element should not be considered textable + */ + notTextable: ['button', 'input[type=checkbox]', 'input[type=radio]'] }; diff --git a/src/canvas/index.js b/src/canvas/index.js index d81f8f603..432bb80e3 100644 --- a/src/canvas/index.js +++ b/src/canvas/index.js @@ -409,11 +409,11 @@ module.exports = () => { * @private */ isInputFocused() { - let contentDocument = this.getFrameEl().contentDocument; - return ( - contentDocument.activeElement && - contentDocument.activeElement.tagName !== 'BODY' - ); + const doc = this.getDocument(); + const toIgnore = ['body', ...this.getConfig().notTextable]; + const focused = doc && doc.activeElement; + + return focused && !toIgnore.some(item => focused.matches(item)); }, /**