Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fixed a problem with IME's(i.e. Japanese IME input) Enter to Co… #1165

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading