Skip to content

Commit

Permalink
Fix CJK IME(like Chinese, Japanese) double input (#4702)
Browse files Browse the repository at this point in the history
* fix: resolve CJK IME double input

* fix: resolve UC mobile no input issue

* feat: add changeset

* Update .changeset/large-melons-warn.md

Co-authored-by: Dylan Schiemann <dylan@dojotoolkit.org>

* fix: more specific way to deal with browsers

Co-authored-by: Dylan Schiemann <dylan@dojotoolkit.org>
  • Loading branch information
ttitoo and dylans authored Dec 5, 2021
1 parent c020ca2 commit 8bc6a46
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/large-melons-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'slate-react': minor
---

Fix CJK IME (e.g. Chinese or Japanese) double input
4 changes: 4 additions & 0 deletions packages/slate-react/src/components/editable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {
IS_FIREFOX_LEGACY,
IS_QQBROWSER,
IS_SAFARI,
IS_UC_MOBILE,
IS_WECHATBROWSER,
CAN_USE_DOM,
} from '../utils/environment'
import { ReactEditor } from '..'
Expand Down Expand Up @@ -772,6 +774,8 @@ export const Editable = (props: EditableProps) => {
!IS_FIREFOX_LEGACY &&
!IS_IOS &&
!IS_QQBROWSER &&
!IS_WECHATBROWSER &&
!IS_UC_MOBILE &&
event.data
) {
Editor.insertText(editor, event.data)
Expand Down
8 changes: 8 additions & 0 deletions packages/slate-react/src/utils/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ export const IS_FIREFOX_LEGACY =
export const IS_QQBROWSER =
typeof navigator !== 'undefined' && /.*QQBrowser/.test(navigator.userAgent)

// UC mobile browser
export const IS_UC_MOBILE =
typeof navigator !== 'undefined' && /.*UCBrowser/.test(navigator.userAgent)

// Wechat browser
export const IS_WECHATBROWSER =
typeof navigator !== 'undefined' && /.*Wechat/.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 = !!(
Expand Down

0 comments on commit 8bc6a46

Please sign in to comment.