Skip to content

Commit 3e63d1c

Browse files
committed
Fix Enter to send in chat
1 parent acea84c commit 3e63d1c

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

app/views/rails_mcp_engine/chat/show.html.erb

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
let conversationHistory = [];
4747

4848
// Load conversation history from localStorage on page load
49-
document.addEventListener('DOMContentLoaded', () => {
49+
function initializeChat() {
5050
// Restore conversation history
5151
const savedHistory = localStorage.getItem('chat_conversation_history');
5252
if (savedHistory) {
@@ -78,15 +78,35 @@ document.addEventListener('DOMContentLoaded', () => {
7878
localStorage.setItem('chat_selected_model', e.target.value);
7979
});
8080
}
81+
}
82+
83+
document.addEventListener('DOMContentLoaded', initializeChat);
84+
85+
function setupChatInput() {
86+
const chatInput = document.getElementById('chat-input');
87+
if (!chatInput) return;
88+
89+
// Idempotent attachment
90+
if (chatInput.dataset.listenerAttached === 'true') return;
91+
92+
chatInput.addEventListener('keydown', handleChatInputKeydown);
93+
chatInput.dataset.listenerAttached = 'true';
94+
}
8195

82-
// Send on Enter (Shift+Enter for new line)
83-
document.getElementById('chat-input').addEventListener('keydown', (e) => {
96+
function handleChatInputKeydown(e) {
8497
if (e.key === 'Enter' && !e.shiftKey) {
98+
if (e.isComposing) return;
8599
e.preventDefault();
86100
sendMessage();
87101
}
88-
});
89-
});
102+
}
103+
104+
// Initialize
105+
if (document.readyState === 'loading') {
106+
document.addEventListener('DOMContentLoaded', setupChatInput);
107+
} else {
108+
setupChatInput();
109+
}
90110

91111
function sendMessage() {
92112
const input = document.getElementById('chat-input');

0 commit comments

Comments
 (0)