File tree Expand file tree Collapse file tree 1 file changed +23
-4
lines changed
app/views/rails_mcp_engine/chat Expand file tree Collapse file tree 1 file changed +23
-4
lines changed Original file line number Diff line number Diff line change @@ -79,14 +79,33 @@ document.addEventListener('DOMContentLoaded', () => {
7979 } ) ;
8080 }
8181
82- // Send on Enter (Shift+Enter for new line)
83- document . getElementById ( 'chat-input' ) . addEventListener ( 'keydown' , ( e ) => {
82+ function setupChatInput ( ) {
83+ const chatInput = document . getElementById ( 'chat-input' ) ;
84+ if ( ! chatInput ) return ;
85+
86+ // Remove existing listener to prevent duplicates if any (though unlikely with this pattern)
87+ // We can't easily remove anonymous functions, but we can ensure we don't attach multiple times
88+ // by checking a data attribute or just relying on the fact that this runs on page load.
89+ // For simplicity in this context, we'll just attach.
90+
91+ chatInput . removeEventListener ( 'keydown' , handleChatInputKeydown ) ;
92+ chatInput . addEventListener ( 'keydown' , handleChatInputKeydown ) ;
93+ }
94+
95+ function handleChatInputKeydown ( e ) {
8496 if ( e . key === 'Enter' && ! e . shiftKey ) {
97+ if ( e . isComposing ) return ; // Ignore Enter during IME composition
8598 e . preventDefault ( ) ;
8699 sendMessage ( ) ;
87100 }
88- } ) ;
89- } ) ;
101+ }
102+
103+ // Initial setup
104+ setupChatInput ( ) ;
105+
106+ // Re-setup on Turbo load if available, or just DOMContentLoaded
107+ document . addEventListener ( 'turbo:load' , setupChatInput ) ;
108+ document . addEventListener ( 'DOMContentLoaded' , setupChatInput ) ;
90109
91110function sendMessage ( ) {
92111 const input = document . getElementById ( 'chat-input' ) ;
You can’t perform that action at this time.
0 commit comments