From 3e6be97ec933a7ddcba821ed7b46778f0deb5971 Mon Sep 17 00:00:00 2001 From: Jiaqing Liang Date: Mon, 16 Mar 2026 13:15:11 +0800 Subject: [PATCH] feat: add IME composition fix for macOS (closes #33) Based on PR #33 by UnsongK. Compressed to 4 lines with OS guard so Windows users are completely unaffected. --- stapp.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/stapp.py b/stapp.py index 99c79e0..a59a8ce 100644 --- a/stapp.py +++ b/stapp.py @@ -82,6 +82,11 @@ if "messages" not in st.session_state: st.session_state.messages = [] for msg in st.session_state.messages: with st.chat_message(msg["role"]): st.markdown(msg["content"], unsafe_allow_html=True) +# IME composition fix (macOS only) - prevents Enter from submitting during CJK input +if os.name != 'nt': + 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