From b3991bbc580dc3568c294fbb2d8903a625dc0d6c Mon Sep 17 00:00:00 2001 From: miukimiu Date: Mon, 20 Apr 2020 12:01:05 +0100 Subject: [PATCH 1/3] Adding a key to the inner text comp --- src/components/code/_code_block.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/components/code/_code_block.tsx b/src/components/code/_code_block.tsx index 8a43067feb2..1b4d60a047e 100644 --- a/src/components/code/_code_block.tsx +++ b/src/components/code/_code_block.tsx @@ -30,7 +30,7 @@ import { EuiOverlayMask } from '../overlay_mask'; import { EuiFocusTrap } from '../focus_trap'; -import { keyCodes } from '../../services'; +import { keyCodes, htmlIdGenerator } from '../../services'; import { EuiI18n } from '../i18n'; import { EuiInnerText } from '../inner_text'; import { keysOf } from '../common'; @@ -339,10 +339,16 @@ export class EuiCodeBlockImpl extends Component { return fullScreenDisplay; }; + /** + * Generates a new key that will help React identify that the code snippet has changed + * So it will be possible to copy the new content + */ + const key = htmlIdGenerator()(); + return ( <> {createPortal(children, this.codeTarget)} - + {(innerTextRef, innerText) => { const codeBlockControls = getCodeBlockControls(innerText); return ( From bd9da268f9cbe39caa71ca2a65cf30385f8c85f7 Mon Sep 17 00:00:00 2001 From: miukimiu Date: Mon, 20 Apr 2020 12:28:34 +0100 Subject: [PATCH 2/3] Adding changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52ef601408c..c402222bb97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Fixed `EuiInMemoryTable` `isClearable` property to initiate reset ([#3328](https://github.com/elastic/eui/pull/3328)) - Fixed `EuiCollapsibleNav` docked states on mobile ([#3330](https://github.com/elastic/eui/pull/3330)) - Fixed `EuiPopover` positioning from being overridden by `style` prop ([#3329](https://github.com/elastic/eui/pull/3329)) +- Fixed `EuiCodeBlock` not copying updated content ([#3351](https://github.com/elastic/eui/pull/3351)) **Breaking changes** From 10df8215a207b9b0c4494c2bbf8eef55e1ce1da9 Mon Sep 17 00:00:00 2001 From: miukimiu Date: Tue, 21 Apr 2020 21:03:22 +0100 Subject: [PATCH 3/3] adding childList to mutation observer config --- src/components/code/_code_block.tsx | 10 ++-------- src/components/inner_text/inner_text.tsx | 1 + 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/components/code/_code_block.tsx b/src/components/code/_code_block.tsx index 1b4d60a047e..8a43067feb2 100644 --- a/src/components/code/_code_block.tsx +++ b/src/components/code/_code_block.tsx @@ -30,7 +30,7 @@ import { EuiOverlayMask } from '../overlay_mask'; import { EuiFocusTrap } from '../focus_trap'; -import { keyCodes, htmlIdGenerator } from '../../services'; +import { keyCodes } from '../../services'; import { EuiI18n } from '../i18n'; import { EuiInnerText } from '../inner_text'; import { keysOf } from '../common'; @@ -339,16 +339,10 @@ export class EuiCodeBlockImpl extends Component { return fullScreenDisplay; }; - /** - * Generates a new key that will help React identify that the code snippet has changed - * So it will be possible to copy the new content - */ - const key = htmlIdGenerator()(); - return ( <> {createPortal(children, this.codeTarget)} - + {(innerTextRef, innerText) => { const codeBlockControls = getCodeBlockControls(innerText); return ( diff --git a/src/components/inner_text/inner_text.tsx b/src/components/inner_text/inner_text.tsx index 5b765ff5400..33bd4a02b07 100644 --- a/src/components/inner_text/inner_text.tsx +++ b/src/components/inner_text/inner_text.tsx @@ -60,6 +60,7 @@ export function useInnerText( observer.observe(ref, { characterData: true, subtree: true, + childList: true, }); } return () => {