Skip to content

Commit c42f641

Browse files
authored
Merge pull request #17 from steelydylan/hotfix/0.3.5
Hotfix/0.3.5
2 parents 7b26e70 + d811c40 commit c42f641

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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",

src/components/Textarea.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)