Skip to content

Commit 1d4e654

Browse files
allozaurpwilkin
authored andcommitted
Prevent premature submission on IME input (ggml-org#16673)
* fix: Prevent premature submission on IME input * chore: update webui static build * refactor: Put IME completion checker in a helper function and add checking for `KeyboardEvent.eventKey === 229` * chore: update webui static build * chore: update webui static build * chore: update webui static build
1 parent e4a83f0 commit 1d4e654

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

tools/server/public/index.html.gz

59 Bytes
Binary file not shown.

tools/server/webui/src/lib/components/app/chat/ChatForm/ChatForm.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
MimeTypeImage,
2727
MimeTypeText
2828
} from '$lib/enums/files';
29+
import { isIMEComposing } from '$lib/utils/is-ime-composing';
2930
3031
interface Props {
3132
class?: string;
@@ -97,7 +98,7 @@
9798
}
9899
99100
async function handleKeydown(event: KeyboardEvent) {
100-
if (event.key === 'Enter' && !event.shiftKey) {
101+
if (event.key === 'Enter' && !event.shiftKey && !isIMEComposing(event)) {
101102
event.preventDefault();
102103
103104
if ((!message.trim() && uploadedFiles.length === 0) || disabled || isLoading) return;

tools/server/webui/src/lib/components/app/chat/ChatMessages/ChatMessage.svelte

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script lang="ts">
22
import { getDeletionInfo } from '$lib/stores/chat.svelte';
33
import { copyToClipboard } from '$lib/utils/copy';
4+
import { isIMEComposing } from '$lib/utils/is-ime-composing';
45
import ChatMessageAssistant from './ChatMessageAssistant.svelte';
56
import ChatMessageUser from './ChatMessageUser.svelte';
67
@@ -93,7 +94,9 @@
9394
}
9495
9596
function handleEditKeydown(event: KeyboardEvent) {
96-
if (event.key === 'Enter' && !event.shiftKey) {
97+
// Check for IME composition using isComposing property and keyCode 229 (specifically for IME composition on Safari)
98+
// This prevents saving edit when confirming IME word selection (e.g., Japanese/Chinese input)
99+
if (event.key === 'Enter' && !event.shiftKey && !isIMEComposing(event)) {
97100
event.preventDefault();
98101
handleSaveEdit();
99102
} else if (event.key === 'Escape') {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export function isIMEComposing(event: KeyboardEvent) {
2+
// Check for IME composition using isComposing property and keyCode 229 (specifically for IME composition on Safari, which is notorious for not supporting KeyboardEvent.isComposing)
3+
// This prevents form submission when confirming IME word selection (e.g., Japanese/Chinese input)
4+
return event.isComposing || event.keyCode === 229;
5+
}

0 commit comments

Comments
 (0)