From d8cfcc9eaec6a2abcac74fb3b3805b0807e9f9bc Mon Sep 17 00:00:00 2001 From: Joel Date: Fri, 12 May 2023 10:56:22 +0800 Subject: [PATCH] fix: input method enter also send message --- app/components/chat/index.tsx | 10 +++++++--- config/index.ts | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/components/chat/index.tsx b/app/components/chat/index.tsx index d1c4d80..96e7d1b 100644 --- a/app/components/chat/index.tsx +++ b/app/components/chat/index.tsx @@ -1,6 +1,6 @@ 'use client' -import type { FC } from 'react' -import React, { useEffect } from 'react' +import type { FC, } from 'react' +import React, { useEffect, useRef } from 'react' import cn from 'classnames' import { HandThumbDownIcon, HandThumbUpIcon } from '@heroicons/react/24/outline' import { useTranslation } from 'react-i18next' @@ -232,6 +232,7 @@ const Chat: FC = ({ }) => { const { t } = useTranslation() const { notify } = Toast + const isUseInputMethod = useRef(false) const [query, setQuery] = React.useState('') const handleContentChange = (e: any) => { @@ -267,12 +268,15 @@ const Chat: FC = ({ const handleKeyUp = (e: any) => { if (e.code === 'Enter') { e.preventDefault() - if (!e.shiftKey) + // prevent send message when using input method enter + if (!e.shiftKey && !isUseInputMethod.current) { handleSend() + } } } const haneleKeyDown = (e: any) => { + isUseInputMethod.current = e.nativeEvent.isComposing if (e.code === 'Enter' && !e.shiftKey) { setQuery(query.replace(/\n$/, '')) e.preventDefault() diff --git a/config/index.ts b/config/index.ts index 0f5d368..e13ac31 100644 --- a/config/index.ts +++ b/config/index.ts @@ -3,7 +3,7 @@ export const APP_ID = '' export const API_KEY = '' export const APP_INFO: AppInfo = { - "title": 'Chat APP', + "title": 'Chat APP11', "description": '', "copyright": '', "privacy_policy": '',