迁移全局弹窗键盘事件

This commit is contained in:
2026-04-25 10:09:56 +08:00
parent 84b3624d59
commit 283793bc1c
2 changed files with 18 additions and 11 deletions
+18
View File
@@ -36,4 +36,22 @@ export function bindGlobalDialogControls() {
window.chatDialog?._cancel?.();
}
});
document.addEventListener("keydown", (event) => {
if (!(event.target instanceof HTMLTextAreaElement) || event.target.id !== "global-dialog-input") {
return;
}
// prompt 输入框沿用旧体验:Enter 确认,Shift+Enter 保留换行,Esc 取消。
if (event.key === "Enter" && !event.shiftKey) {
event.preventDefault();
window.chatDialog?._confirm?.();
return;
}
if (event.key === "Escape") {
event.preventDefault();
window.chatDialog?._cancel?.();
}
});
}
@@ -220,15 +220,4 @@
},
};
})();
// prompt 模式支持按 Enter 确认、Esc 取消
document.getElementById('global-dialog-input').addEventListener('keydown', function(e) {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
window.chatDialog._confirm();
} else if (e.key === 'Escape') {
e.preventDefault();
window.chatDialog._cancel();
}
});
</script>