File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11{
22 "name" : " react-split-mde" ,
3- "version" : " 0.3.4 " ,
3+ "version" : " 0.3.5 " ,
44 "description" : " " ,
55 "main" : " ./lib/index.js" ,
66 "types" : " ./lib/index.d.ts" ,
Original file line number Diff line number Diff line change @@ -232,13 +232,27 @@ export const Textarea = React.forwardRef(
232232 } ) ;
233233 } , [ markdown ] ) ;
234234
235+ /**
236+ * 変換中かどうか(isComposing)を適切に取得する
237+ * - Safariだとkeydownの前にcompositionEndが発火される
238+ * => 変換確定時のkeydownにおいてisComposingの値が適切ではない(変換確定のEnterキーでhandleKeyDownがcomposing:falseとして呼ばれてしまう)
239+ * => keyupイベントで変換終了を確認することで対応
240+ * - Chromeだとkeyupイベントの後にcompositionStartが発火される
241+ * => キーを離す前にEnterを押されると変換中であると認識されない
242+ * => keydownイベントで変換開始を確認することで対応
243+ */
235244 useEffect ( ( ) => {
236- const checkComposing = ( e : KeyboardEvent ) => {
237- composing . current = e . isComposing ;
245+ const checkComposingStart = ( e : KeyboardEvent ) => {
246+ if ( e . isComposing ) composing . current = true ;
238247 } ;
239- htmlRef . current . addEventListener ( "keyup" , checkComposing ) ;
248+ const checkComposingEnd = ( e : KeyboardEvent ) => {
249+ if ( ! e . isComposing ) composing . current = false ;
250+ } ;
251+ htmlRef . current . addEventListener ( "keydown" , checkComposingStart ) ;
252+ htmlRef . current . addEventListener ( "keyup" , checkComposingEnd ) ;
240253 return ( ) => {
241- htmlRef . current ?. removeEventListener ( "keyup" , checkComposing ) ;
254+ htmlRef . current ?. removeEventListener ( "keydown" , checkComposingStart ) ;
255+ htmlRef . current ?. removeEventListener ( "keyup" , checkComposingEnd ) ;
242256 } ;
243257 } , [ ] ) ;
244258
You can’t perform that action at this time.
0 commit comments