From 8d960b7a40de6803f25ed8838cb086a04d059bec Mon Sep 17 00:00:00 2001 From: syui Date: Sun, 15 Jun 2025 23:33:22 +0900 Subject: [PATCH] fix ask-ai enter --- my-blog/static/js/ask-ai.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/my-blog/static/js/ask-ai.js b/my-blog/static/js/ask-ai.js index a562eac..ea23332 100644 --- a/my-blog/static/js/ask-ai.js +++ b/my-blog/static/js/ask-ai.js @@ -253,6 +253,20 @@ function setupAskAIEventListeners() { handleAIResponse(event.detail); }); + // Track IME composition state + let isComposing = false; + const aiQuestionInput = document.getElementById('aiQuestion'); + + if (aiQuestionInput) { + aiQuestionInput.addEventListener('compositionstart', function() { + isComposing = true; + }); + + aiQuestionInput.addEventListener('compositionend', function() { + isComposing = false; + }); + } + // Keyboard shortcuts document.addEventListener('keydown', function(e) { if (e.key === 'Escape') { @@ -263,7 +277,7 @@ function setupAskAIEventListeners() { } // Enter key to send message (only when not composing Japanese input) - if (e.key === 'Enter' && e.target.id === 'aiQuestion' && !e.shiftKey && !e.isComposing) { + if (e.key === 'Enter' && e.target.id === 'aiQuestion' && !e.shiftKey && !isComposing) { e.preventDefault(); askQuestion(); }