Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const getScript = (isTelemetryEnabled: boolean) => `<script>
let selectedFileIndex = -1;
let planModeEnabled = false;
let thinkingModeEnabled = false;
let isComposing = false;
let lastEnterTime = 0;
const ENTER_THROTTLE_MS = 50;

function shouldAutoScroll(messagesDiv) {
const threshold = 100; // pixels from bottom
Expand Down Expand Up @@ -873,9 +876,31 @@ const getScript = (isTelemetryEnabled: boolean) => `<script>
});
}, 500); // Save after 500ms of no typing
});


// Handle IME composition events (Korean, Japanese, Chinese input)
messageInput.addEventListener('compositionstart', () => {
isComposing = true;
});

messageInput.addEventListener('compositionend', () => {
isComposing = false;
});

messageInput.addEventListener('keydown', (e) => {
if (e.key === 'Enter' && !e.shiftKey) {
// Prevent duplicate submission during IME composition (Korean, Japanese, Chinese)
if (isComposing || e.isComposing) {
return;
}

// Throttle rapid Enter presses (safety net)
const now = Date.now();
if (now - lastEnterTime < ENTER_THROTTLE_MS) {
e.preventDefault();
return;
}
lastEnterTime = now;

e.preventDefault();
const sendBtn = document.getElementById('sendBtn');
if (sendBtn.disabled){
Expand Down