From 935b3a79d6ec7d7e8f20804b2703e984e9c396e0 Mon Sep 17 00:00:00 2001 From: Dylan Schiemann Date: Fri, 13 Aug 2021 04:46:06 -0700 Subject: [PATCH] fix: chinese input double in qq browser (#4452) * fix: chinese input double in qq browser * add changeset * update changeset --- .changeset/flat-carpets-sort.md | 5 +++++ packages/slate-react/src/components/editable.tsx | 9 ++++++++- packages/slate-react/src/utils/environment.ts | 4 ++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 .changeset/flat-carpets-sort.md diff --git a/.changeset/flat-carpets-sort.md b/.changeset/flat-carpets-sort.md new file mode 100644 index 0000000000..d9fe8e09c4 --- /dev/null +++ b/.changeset/flat-carpets-sort.md @@ -0,0 +1,5 @@ +--- +'slate-react': patch +--- + +double ime fix for qq browser diff --git a/packages/slate-react/src/components/editable.tsx b/packages/slate-react/src/components/editable.tsx index 6393f10586..8788b32a83 100644 --- a/packages/slate-react/src/components/editable.tsx +++ b/packages/slate-react/src/components/editable.tsx @@ -21,6 +21,7 @@ import { IS_CHROME, IS_FIREFOX, IS_FIREFOX_LEGACY, + IS_QQBROWSER, IS_SAFARI, } from '../utils/environment' import { ReactEditor } from '..' @@ -714,7 +715,13 @@ export const Editable = (props: EditableProps) => { // aren't correct and never fire the "insertFromComposition" // type that we need. So instead, insert whenever a composition // ends since it will already have been committed to the DOM. - if (!IS_SAFARI && !IS_FIREFOX_LEGACY && !IS_IOS && event.data) { + if ( + !IS_SAFARI && + !IS_FIREFOX_LEGACY && + !IS_IOS && + !IS_QQBROWSER && + event.data + ) { Editor.insertText(editor, event.data) } } diff --git a/packages/slate-react/src/utils/environment.ts b/packages/slate-react/src/utils/environment.ts index 9a64c40625..3dcbab9d26 100644 --- a/packages/slate-react/src/utils/environment.ts +++ b/packages/slate-react/src/utils/environment.ts @@ -39,6 +39,10 @@ export const IS_FIREFOX_LEGACY = navigator.userAgent ) +// qq browser +export const IS_QQBROWSER = + typeof navigator !== 'undefined' && /.*QQBrowser/.test(navigator.userAgent) + // Check if DOM is available as React does internally. // https://github.com/facebook/react/blob/master/packages/shared/ExecutionEnvironment.js export const CAN_USE_DOM = !!(