From ad0730f05f7aa1e6b6bfafb76b590a01b3bd58ab Mon Sep 17 00:00:00 2001 From: Jainil Parekh Date: Tue, 17 Dec 2019 06:20:10 -0800 Subject: [PATCH] Fix DOMObserver mutation data for IE Summary: IE 11 considers the enter keypress that concludes the composition as an input char, which ends up adding a new line to the editor. I am adding code to strip that newline character when processing the mutation event. Differential Revision: D19141003 fbshipit-source-id: fdda84cc70eb5eb5741ee1815d0cad0049354ad9 --- src/component/handlers/composition/DOMObserver.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/component/handlers/composition/DOMObserver.js b/src/component/handlers/composition/DOMObserver.js index 099daedd6c..da0b8ec7fe 100644 --- a/src/component/handlers/composition/DOMObserver.js +++ b/src/component/handlers/composition/DOMObserver.js @@ -110,6 +110,12 @@ class DOMObserver { // These events are also followed by a `childList`, which is the one // we are able to retrieve the offsetKey and apply the '' text. if (target.textContent !== '') { + // IE 11 considers the enter keypress that concludes the composition + // as an input char. This strips that newline character so the draft + // state does not receive spurious newlines. + if (USE_CHAR_DATA) { + return target.textContent.replace('\n', ''); + } return target.textContent; } } else if (type === 'childList') {