-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ui): IME composition detection not working (#17476)
- Loading branch information
Showing
1 changed file
with
2 additions
and
19 deletions.
There are no files selected for viewing
21 changes: 2 additions & 19 deletions
21
ui/src/composables/private.use-key-composition/use-key-composition.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,12 @@ | ||
import { client } from '../../plugins/platform/Platform.js' | ||
|
||
const isJapanese = /[\u3000-\u303f\u3040-\u309f\u30a0-\u30ff\uff00-\uff9f\u4e00-\u9faf\u3400-\u4dbf]/ | ||
const isChinese = /[\u4e00-\u9fff\u3400-\u4dbf\u{20000}-\u{2a6df}\u{2a700}-\u{2b73f}\u{2b740}-\u{2b81f}\u{2b820}-\u{2ceaf}\uf900-\ufaff\u3300-\u33ff\ufe30-\ufe4f\uf900-\ufaff\u{2f800}-\u{2fa1f}]/u | ||
const isKorean = /[\u3131-\u314e\u314f-\u3163\uac00-\ud7a3]/ | ||
const isPlainText = /[a-z0-9_ -]$/i | ||
|
||
export default function (onInput) { | ||
return function onComposition (e) { | ||
if (e.type === 'compositionend' || e.type === 'change') { | ||
if (e.target.qComposing !== true) return | ||
e.target.qComposing = false | ||
onInput(e) | ||
} | ||
else if ( | ||
e.type === 'compositionupdate' | ||
&& e.target.qComposing !== true | ||
&& typeof e.data === 'string' | ||
) { | ||
const isComposing = client.is.firefox === true | ||
? isPlainText.test(e.data) === false | ||
: isJapanese.test(e.data) === true || isChinese.test(e.data) === true || isKorean.test(e.data) === true | ||
|
||
if (isComposing === true) { | ||
e.target.qComposing = true | ||
} | ||
else if (e.type === 'compositionstart') { | ||
e.target.qComposing = true | ||
} | ||
} | ||
} |