fix(frontend): prevent submit during IME composition (#1562)
This commit is contained in:
parent
f3799ff9cc
commit
52f482503a
|
|
@ -20,6 +20,7 @@ import { checkAgentName, getAgent } from "@/core/agents/api";
|
||||||
import { useI18n } from "@/core/i18n/hooks";
|
import { useI18n } from "@/core/i18n/hooks";
|
||||||
import { useThreadStream } from "@/core/threads/hooks";
|
import { useThreadStream } from "@/core/threads/hooks";
|
||||||
import { uuid } from "@/core/utils/uuid";
|
import { uuid } from "@/core/utils/uuid";
|
||||||
|
import { isIMEComposing } from "@/lib/ime";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
type Step = "name" | "chat";
|
type Step = "name" | "chat";
|
||||||
|
|
@ -98,7 +99,7 @@ export default function NewAgentPage() {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const handleNameKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
const handleNameKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
||||||
if (e.key === "Enter") {
|
if (e.key === "Enter" && !isIMEComposing(e)) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
void handleConfirmName();
|
void handleConfirmName();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ import {
|
||||||
SelectTrigger,
|
SelectTrigger,
|
||||||
SelectValue,
|
SelectValue,
|
||||||
} from "@/components/ui/select";
|
} from "@/components/ui/select";
|
||||||
|
import { isIMEComposing } from "@/lib/ime";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import type { ChatStatus, FileUIPart } from "ai";
|
import type { ChatStatus, FileUIPart } from "ai";
|
||||||
import {
|
import {
|
||||||
|
|
@ -833,7 +834,7 @@ export const PromptInputTextarea = ({
|
||||||
|
|
||||||
const handleKeyDown: KeyboardEventHandler<HTMLTextAreaElement> = (e) => {
|
const handleKeyDown: KeyboardEventHandler<HTMLTextAreaElement> = (e) => {
|
||||||
if (e.key === "Enter") {
|
if (e.key === "Enter") {
|
||||||
if (isComposing || e.nativeEvent.isComposing) {
|
if (isIMEComposing(e, isComposing)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (e.shiftKey) {
|
if (e.shiftKey) {
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,7 @@ import {
|
||||||
import type { AgentThread, AgentThreadState } from "@/core/threads/types";
|
import type { AgentThread, AgentThreadState } from "@/core/threads/types";
|
||||||
import { pathOfThread, titleOfThread } from "@/core/threads/utils";
|
import { pathOfThread, titleOfThread } from "@/core/threads/utils";
|
||||||
import { env } from "@/env";
|
import { env } from "@/env";
|
||||||
|
import { isIMEComposing } from "@/lib/ime";
|
||||||
|
|
||||||
export function RecentChatList() {
|
export function RecentChatList() {
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
|
@ -271,7 +272,8 @@ export function RecentChatList() {
|
||||||
onChange={(e) => setRenameValue(e.target.value)}
|
onChange={(e) => setRenameValue(e.target.value)}
|
||||||
placeholder={t.common.rename}
|
placeholder={t.common.rename}
|
||||||
onKeyDown={(e) => {
|
onKeyDown={(e) => {
|
||||||
if (e.key === "Enter") {
|
if (e.key === "Enter" && !isIMEComposing(e)) {
|
||||||
|
e.preventDefault();
|
||||||
handleRenameSubmit();
|
handleRenameSubmit();
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
import type { KeyboardEvent } from "react";
|
||||||
|
|
||||||
|
type IMEKeyboardEvent = KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>;
|
||||||
|
|
||||||
|
export function isIMEComposing(
|
||||||
|
event: IMEKeyboardEvent,
|
||||||
|
isComposing = false,
|
||||||
|
): boolean {
|
||||||
|
return isComposing || event.nativeEvent.isComposing || event.keyCode === 229;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue