mirror of
https://github.com/aljazceru/goose.git
synced 2025-12-22 00:24:23 +01:00
fix: Fixed a problem with IME's(i.e. Japanese IME input) Enter to Co… (#1165)
This commit is contained in:
@@ -17,6 +17,8 @@ export default function Input({
|
|||||||
onStop,
|
onStop,
|
||||||
}: InputProps) {
|
}: InputProps) {
|
||||||
const [value, setValue] = useState('');
|
const [value, setValue] = useState('');
|
||||||
|
// State to track if the IME is composing (i.e., in the middle of Japanese IME input)
|
||||||
|
const [isComposing, setIsComposing] = useState(false);
|
||||||
const textAreaRef = useRef<HTMLTextAreaElement>(null);
|
const textAreaRef = useRef<HTMLTextAreaElement>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -41,12 +43,22 @@ export default function Input({
|
|||||||
useAutosizeTextArea(textAreaRef.current, value);
|
useAutosizeTextArea(textAreaRef.current, value);
|
||||||
|
|
||||||
const handleChange = (evt: React.ChangeEvent<HTMLTextAreaElement>) => {
|
const handleChange = (evt: React.ChangeEvent<HTMLTextAreaElement>) => {
|
||||||
const val = evt.target?.value;
|
const val = evt.target.value;
|
||||||
setValue(val);
|
setValue(val);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Handlers for composition events, which are crucial for proper IME behavior
|
||||||
|
const handleCompositionStart = (evt: React.CompositionEvent<HTMLTextAreaElement>) => {
|
||||||
|
setIsComposing(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleCompositionEnd = (evt: React.CompositionEvent<HTMLTextAreaElement>) => {
|
||||||
|
setIsComposing(false);
|
||||||
|
};
|
||||||
|
|
||||||
const handleKeyDown = (evt: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
const handleKeyDown = (evt: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
||||||
if (evt.key === 'Enter' && !evt.shiftKey) {
|
// Only trigger submit on Enter if not composing (IME input in progress) and shift is not pressed
|
||||||
|
if (evt.key === 'Enter' && !evt.shiftKey && !isComposing) {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
if (value.trim()) {
|
if (value.trim()) {
|
||||||
handleSubmit(new CustomEvent('submit', { detail: { value } }));
|
handleSubmit(new CustomEvent('submit', { detail: { value } }));
|
||||||
@@ -76,18 +88,14 @@ export default function Input({
|
|||||||
onSubmit={onFormSubmit}
|
onSubmit={onFormSubmit}
|
||||||
className="flex relative h-auto px-[16px] pr-[68px] py-[1rem] border-t border-borderSubtle"
|
className="flex relative h-auto px-[16px] pr-[68px] py-[1rem] border-t border-borderSubtle"
|
||||||
>
|
>
|
||||||
{/* loading */}
|
|
||||||
{/* {isLoading && (
|
|
||||||
<div className="absolute top-[-2px] left-0 w-full h-[2px]">
|
|
||||||
<div className="absolute w-[300px] h-[2px] bg-gradient-to-r from-blockTeal to-blockOrange animate-gradient-loader"></div>
|
|
||||||
</div>
|
|
||||||
)} */}
|
|
||||||
<textarea
|
<textarea
|
||||||
autoFocus
|
autoFocus
|
||||||
id="dynamic-textarea"
|
id="dynamic-textarea"
|
||||||
placeholder="What can goose help with?"
|
placeholder="What can goose help with?"
|
||||||
value={value}
|
value={value}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
|
onCompositionStart={handleCompositionStart}
|
||||||
|
onCompositionEnd={handleCompositionEnd}
|
||||||
onKeyDown={handleKeyDown}
|
onKeyDown={handleKeyDown}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
ref={textAreaRef}
|
ref={textAreaRef}
|
||||||
|
|||||||
Reference in New Issue
Block a user