From dca9b192404353736f9e28d2eec188731a0014b0 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Mon, 26 Mar 2018 22:44:24 +0200 Subject: [PATCH] Better disabled detection --- .../client/components/rte/features/Bold.js | 5 +++-- .../client/components/rte/features/Italic.js | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/plugins/talk-plugin-rich-text/client/components/rte/features/Bold.js b/plugins/talk-plugin-rich-text/client/components/rte/features/Bold.js index 8f5b55de5..fe072e2b1 100644 --- a/plugins/talk-plugin-rich-text/client/components/rte/features/Bold.js +++ b/plugins/talk-plugin-rich-text/client/components/rte/features/Bold.js @@ -1,5 +1,5 @@ import createToggle from '../factories/createToggle'; -import { findIntersecting } from '../lib/dom'; +import { findIntersecting, findAncestor } from '../lib/dom'; const boldTags = ['B', 'STRONG']; @@ -21,7 +21,8 @@ function isDisabled() { n => n.nodeName !== '#text' && window.getComputedStyle(n).getPropertyValue('font-weight') === 'bold' && - !boldTags.includes(n.tagName), + !boldTags.includes(n.tagName) && + !findAncestor(n, n => boldTags.includes(n.tagName), this.container), this.container ); } diff --git a/plugins/talk-plugin-rich-text/client/components/rte/features/Italic.js b/plugins/talk-plugin-rich-text/client/components/rte/features/Italic.js index d35f08da0..80703f47c 100644 --- a/plugins/talk-plugin-rich-text/client/components/rte/features/Italic.js +++ b/plugins/talk-plugin-rich-text/client/components/rte/features/Italic.js @@ -1,5 +1,5 @@ import createToggle from '../factories/createToggle'; -import { findIntersecting } from '../lib/dom'; +import { findIntersecting, findAncestor } from '../lib/dom'; const italicTags = ['I', 'EM']; @@ -19,7 +19,8 @@ function isDisabled() { n => n.nodeName !== '#text' && window.getComputedStyle(n).getPropertyValue('font-style') === 'italic' && - !italicTags.includes(n.tagName), + !italicTags.includes(n.tagName) && + !findAncestor(n, n => italicTags.includes(n.tagName), this.container), this.container ); }