Skip to content

Commit 304cd76

Browse files
robbertbrakmmissey
authored andcommitted
Fix typing Chinese in Edge (facebookarchive#2082) (facebookarchive#2088)
Summary: Fixes facebookarchive#2082. Pull Request resolved: facebookarchive#2088 Differential Revision: D18698264 Pulled By: mrkev fbshipit-source-id: f5f5d4e4a0ff66a9fef62976af8726660411a106
1 parent e3c1feb commit 304cd76

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/component/handlers/composition/DOMObserver.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,19 @@ class DOMObserver {
113113
return target.textContent;
114114
}
115115
} else if (type === 'childList') {
116-
// `characterData` events won't happen or are ignored when
117-
// removing the last character of a leaf node, what happens
118-
// instead is a `childList` event with a `removedNodes` array.
119-
// For this case the textContent should be '' and
120-
// `DraftModifier.replaceText` will make sure the content is
121-
// updated properly.
122116
if (removedNodes && removedNodes.length) {
117+
// `characterData` events won't happen or are ignored when
118+
// removing the last character of a leaf node, what happens
119+
// instead is a `childList` event with a `removedNodes` array.
120+
// For this case the textContent should be '' and
121+
// `DraftModifier.replaceText` will make sure the content is
122+
// updated properly.
123123
return '';
124+
} else if (target.textContent !== '') {
125+
// Typing Chinese in an empty block in MS Edge results in a
126+
// `childList` event with non-empty textContent.
127+
// See https://github.com/facebook/draft-js/issues/2082
128+
return target.textContent;
124129
}
125130
}
126131
return null;

src/component/handlers/composition/__tests__/DraftEditorCompostionHandler-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function getEditorStateFromHTML(html: string) {
6767
const state =
6868
blocksFromHTML != null
6969
? ContentState.createFromBlockArray(
70-
blocksFromHTML.contentBlocks ?? [],
70+
blocksFromHTML.contentBlocks || [],
7171
blocksFromHTML.entityMap,
7272
)
7373
: ContentState.createEmpty();

0 commit comments

Comments
 (0)