Skip to content

Commit

Permalink
fix: Fixed a problem with IME's(i.e. Japanese IME input) Enter to Co… (
Browse files Browse the repository at this point in the history
  • Loading branch information
higumachan authored Feb 10, 2025
1 parent 54618e7 commit 18524c1
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions ui/desktop/src/components/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export default function Input({
onStop,
}: InputProps) {
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);

useEffect(() => {
Expand All @@ -41,12 +43,22 @@ export default function Input({
useAutosizeTextArea(textAreaRef.current, value);

const handleChange = (evt: React.ChangeEvent<HTMLTextAreaElement>) => {
const val = evt.target?.value;
const val = evt.target.value;
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>) => {
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();
if (value.trim()) {
handleSubmit(new CustomEvent('submit', { detail: { value } }));
Expand Down Expand Up @@ -76,18 +88,14 @@ export default function Input({
onSubmit={onFormSubmit}
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
autoFocus
id="dynamic-textarea"
placeholder="What can goose help with?"
value={value}
onChange={handleChange}
onCompositionStart={handleCompositionStart}
onCompositionEnd={handleCompositionEnd}
onKeyDown={handleKeyDown}
disabled={disabled}
ref={textAreaRef}
Expand Down

0 comments on commit 18524c1

Please sign in to comment.