From 4d0b8e3723e56713ef1b14685acbfd324c9dec84 Mon Sep 17 00:00:00 2001 From: UnsongK Date: Sun, 15 Mar 2026 15:35:17 +0800 Subject: [PATCH] fix: prevent Enter from submitting during IME composition When using CJK input methods, pressing Enter to confirm character selection was incorrectly triggering form submission. This fix listens for compositionstart/compositionend events and blocks Enter keydown during active IME composition. --- stapp.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/stapp.py b/stapp.py index 99c79e0..d3d867d 100644 --- a/stapp.py +++ b/stapp.py @@ -82,6 +82,38 @@ def agent_backend_stream(prompt): for msg in st.session_state.messages: with st.chat_message(msg["role"]): st.markdown(msg["content"], unsafe_allow_html=True) +# Fix: prevent Enter key from submitting during IME composition (e.g. Chinese/Japanese input) +import streamlit.components.v1 as components +components.html(""" + +""", height=0) + if prompt := st.chat_input("请输入指令"): st.session_state.messages.append({"role": "user", "content": prompt}) with st.chat_message("user"): st.markdown(prompt, unsafe_allow_html=False) # 小心 XSS