Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Fix typing Chinese in Edge (#2082) #2088

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/component/handlers/composition/DOMObserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,19 @@ class DOMObserver {
return target.textContent;
}
} else if (type === 'childList') {
// `characterData` events won't happen or are ignored when
// removing the last character of a leaf node, what happens
// instead is a `childList` event with a `removedNodes` array.
// For this case the textContent should be '' and
// `DraftModifier.replaceText` will make sure the content is
// updated properly.
if (removedNodes && removedNodes.length) {
// `characterData` events won't happen or are ignored when
// removing the last character of a leaf node, what happens
// instead is a `childList` event with a `removedNodes` array.
// For this case the textContent should be '' and
// `DraftModifier.replaceText` will make sure the content is
// updated properly.
return '';
} else if (target.textContent !== '') {
// Typing Chinese in an empty block in MS Edge results in a
// `childList` event with non-empty textContent.
// See https://github.com/facebook/draft-js/issues/2082
return target.textContent;
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function getEditorStateFromHTML(html: string) {
const state =
blocksFromHTML != null
? ContentState.createFromBlockArray(
blocksFromHTML.contentBlocks ?? [],
blocksFromHTML.contentBlocks || [],
blocksFromHTML.entityMap,
)
: ContentState.createEmpty();
Expand Down