Skip to content

Commit 9c84995

Browse files
committed
fix: 修复input框在mac下,中文输入发输入英文按下回车确认后直接退出了编辑状态的问题
1 parent 3857c95 commit 9c84995

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

app/src/core/render/domElement/inputElement.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,21 @@ export class InputElement {
9494
isComposing = true;
9595
});
9696
inputElement.addEventListener("compositionend", () => {
97-
isComposing = false;
97+
// 防止此事件早于enter键按下触发(Mac的bug)
98+
setTimeout(() => {
99+
isComposing = false;
100+
}, 100);
98101
});
99-
100102
inputElement.addEventListener("keydown", (event) => {
101103
event.stopPropagation();
102-
if (event.key === "Enter" && !isComposing) {
103-
resolve(inputElement.value);
104-
onChange(inputElement.value);
105-
document.body.removeEventListener("mousedown", onOutsideClick);
106-
removeElement();
104+
105+
if (event.key === "Enter") {
106+
if (!(event.isComposing || isComposing)) {
107+
resolve(inputElement.value);
108+
onChange(inputElement.value);
109+
document.body.removeEventListener("mousedown", onOutsideClick);
110+
removeElement();
111+
}
107112
}
108113
if (event.key === "Tab") {
109114
// 防止tab切换到其他按钮

0 commit comments

Comments
 (0)