Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { ChatStatus, FileUIPart } from "ai";
import type React from "react";
import type { ReactNode } from "react";
import { useCallback, useRef, useState } from "react";
import { useFocusPromptOnPane } from "renderer/components/Chat/ChatInterface/hooks/useFocusPromptOnPane";
import { useHotkeyText } from "renderer/stores/hotkeys";
import type { SlashCommand } from "../../hooks/useSlashCommands";
import type { ModelOption, PermissionMode } from "../../types";
Expand Down Expand Up @@ -74,6 +75,7 @@ export function ChatInputFooter({
onStop,
onSlashCommandSend,
}: ChatInputFooterProps) {
useFocusPromptOnPane(isFocused);
const [issueLinkOpen, setIssueLinkOpen] = useState(false);
const [linkedIssues, setLinkedIssues] = useState<LinkedIssue[]>([]);
const inputRootRef = useRef<HTMLDivElement>(null);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { usePromptInputController } from "@superset/ui/ai-elements/prompt-input";
import { useEffect } from "react";

export function useFocusPromptOnPane(isFocused: boolean) {
const { textInput } = usePromptInputController();

useEffect(() => {
if (isFocused) {
textInput.focus();
}
}, [isFocused, textInput]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type { ReactNode } from "react";
import { useCallback, useRef, useState } from "react";
import { IssueLinkCommand } from "renderer/components/Chat/ChatInterface/components/IssueLinkCommand";
import { SlashCommandInput } from "renderer/components/Chat/ChatInterface/components/SlashCommandInput";
import { useFocusPromptOnPane } from "renderer/components/Chat/ChatInterface/hooks/useFocusPromptOnPane";
import type { SlashCommand } from "renderer/components/Chat/ChatInterface/hooks/useSlashCommands";
import type {
ModelOption,
Expand Down Expand Up @@ -81,6 +82,7 @@ export function ChatInputFooter({
onStop,
onSlashCommandSend,
}: ChatInputFooterProps) {
useFocusPromptOnPane(isFocused);
const [issueLinkOpen, setIssueLinkOpen] = useState(false);
const [linkedIssues, setLinkedIssues] = useState<LinkedIssue[]>([]);
const inputRootRef = useRef<HTMLDivElement>(null);
Expand Down
14 changes: 13 additions & 1 deletion packages/ui/src/components/ai-elements/prompt-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ export function PromptInputProvider({
const clearInput = useCallback(() => setTextInput(""), []);
const textareaRef = useRef<HTMLTextAreaElement | null>(null);
const focus = useCallback(() => {
textareaRef.current?.focus();
const el = textareaRef.current;
if (!el) return;
el.focus();
const len = el.value.length;
el.setSelectionRange(len, len);
}, []);
const __registerTextarea = useCallback(
(ref: RefObject<HTMLTextAreaElement | null>) => {
Expand Down Expand Up @@ -960,6 +964,14 @@ export const PromptInputTextarea = ({
}, [controller]);

const handleKeyDown: KeyboardEventHandler<HTMLTextAreaElement> = (e) => {
// Prevent modifier+arrow combos from bubbling to pane-navigation hotkeys
if (
(e.key === "ArrowLeft" || e.key === "ArrowRight") &&
(e.metaKey || e.ctrlKey)
) {
e.stopPropagation();
}

if (e.key === "Enter") {
if (isComposing || e.nativeEvent.isComposing) {
return;
Expand Down
Loading