Skip to content

An open-source, faster Devin alternative

TypeScript

feat(web): shared ChatTextarea for all 'send a message' inputs

Igor Zalutski8d34301ac2e0
diff --git a/web/src/components/chat-textarea.tsx b/web/src/components/chat-textarea.tsx
new file mode 100644
index 00000000..9c1d5e5b
--- /dev/null
+++ b/web/src/components/chat-textarea.tsx
@@ -0,0 +1,50 @@
+import { useLayoutEffect, useRef, type ComponentProps } from 'react'
+import { Textarea } from '@/components/form'
+import { cn } from '@/lib/utils'
+
+type ChatTextareaProps = ComponentProps<typeof Textarea> & {
+ /** Fired when the user presses Enter (or ⌘/Ctrl+Enter). Shift+Enter inserts a
+ * newline. The caller decides whether to actually send (e.g. guard on
+ * non-empty / not in-flight); a disabled textarea never fires this. */
+ onSend?: () => void
+}
+
+/** Chat-style textarea: auto-grows with its content (up to ~6 rows, then
+ * scrolls) and sends on Enter, newline on Shift+Enter. One home for the
+ * keyboard + sizing semantics so every "send a message" box — steer, start
+ * session — behaves the same. (Not for multi-field forms, where Enter must not
+ * submit; use the plain Textarea there.) */
+export function ChatTextarea({
+ onSend,
+ value,
+ onKeyDown,
+ className,
+ ...props
+}: ChatTextareaProps) {
+ const ref = useRef<HTMLTextAreaElement>(null)
+ // Grow to fit content (cap, then scroll); shrink back when cleared after send.
+ useLayoutEffect(() => {
+ const el = ref.current
+ if (!el) return
+ el.style.height = 'auto'
+ el.style.height = `${Math.min(el.scrollHeight, 160)}px`
+ }, [value])
+ return (
+ <Textarea
+ ref={ref}
+ value={value}
+ rows={1}
+ onKeyDown={(e) => {
+ onKeyDown?.(e)
+ // Enter (or ⌘/Ctrl+Enter) sends; Shift+Enter is a newline. Skip Enter
+ // mid-IME-composition so CJK/accent input isn't cut off.
+ if (e.key === 'Enter' && !e.shiftKey && !e.nativeEvent.isComposing) {
+ e.preventDefault()
+ onSend?.()
+ }
+ }}
+ className={cn('max-h-40 overflow-y-auto', className)}
+ {...props}
+ />
+ )
+}
diff --git a/web/src/pages/AgentDetail.tsx b/web/src/pages/AgentDetail.tsx
index 2e09bc3e..9c30f3bf 100644
--- a/web/src/pages/AgentDetail.tsx
+++ b/web/src/pages/AgentDetail.tsx
@@ -22,6 +22,7 @@ import {
} from '@/components/panel'
import { Button } from '@/components/ui/button'
import { Field, Input, Select, Textarea } from '@/components/form'
+import { ChatTextarea } from '@/components/chat-textarea'
import { StatusBadge } from '@/components/status-badge'
import { EmptyState } from '@/components/empty-state'
import { ResourceTable, type Column } from '@/components/resource-table'
@@ -423,9 +424,14 @@ export default function AgentDetail() {
if (task.trim()) startMutation.mutate()
}}
>
- <Textarea
+ <ChatTextarea
value={task}
onChange={(e) => setTask(e.target.value)}
+ onSend={() => {
+ if (task.trim() && !startMutation.isPending) {
+ startMutation.mutate()
+ }
+ }}
placeholder="Give this agent a task — it runs durably as a new session…"
className="min-h-20"
/>
@@ -433,6 +439,7 @@ export default function AgentDetail() {
<Button
type="submit"
size="sm"
+ title="Enter to start · Shift+Enter for newline"
disabled={startMutation.isPending || !task.trim()}
>
<Send className="size-4" />
diff --git a/web/src/pages/SessionDetail.tsx b/web/src/pages/SessionDetail.tsx
index 6bfbf97d..26111810 100644
--- a/web/src/pages/SessionDetail.tsx
+++ b/web/src/pages/SessionDetail.tsx
@@ -14,7 +14,7 @@ import {
import { SessionEventSchema } from '@/api/schemas'
import { Panel } from '@/components/panel'
import { Button } from '@/components/ui/button'
-import { Textarea } from '@/components/form'
+import { ChatTextarea } from '@/components/chat-textarea'
import { Skeleton } from '@/components/ui/skeleton'
import { StatusBadge } from '@/components/status-badge'
import { EmptyState } from '@/components/empty-state'
@@ -297,9 +297,14 @@ export default function SessionDetail() {
if (draft.trim() && canSteer) steerMutation.mutate()
}}
>
- <Textarea
+ <ChatTextarea
value={draft}
onChange={(e) => setDraft(e.target.value)}
+ onSend={() => {
+ if (draft.trim() && canSteer && !steerMutation.isPending) {
+ steerMutation.mutate()
+ }
+ }}
placeholder={
canSteer
? 'Send a message to steer the session…'
@@ -307,10 +312,10 @@ export default function SessionDetail() {
}
disabled={!canSteer}
className="min-h-10 flex-1"
- rows={1}
/>
<Button
type="submit"
+ title="Enter to send · Shift+Enter for newline"
disabled={!draft.trim() || !canSteer || steerMutation.isPending}
>
<Send className="size-4" />
diff --git a/web/src/pages/Sessions.tsx b/web/src/pages/Sessions.tsx
index 0bf7ba3b..c9c40b9e 100644
--- a/web/src/pages/Sessions.tsx
+++ b/web/src/pages/Sessions.tsx
@@ -16,7 +16,8 @@ import {
DialogHeader,
DialogTitle,
} from '@/components/ui/dialog'
-import { Field, Label, Select, Textarea } from '@/components/form'
+import { Field, Label, Select } from '@/components/form'
+import { ChatTextarea } from '@/components/chat-textarea'
import { StatusBadge } from '@/components/status-badge'
import { EmptyState } from '@/components/empty-state'
import { ResourceTable, type Column } from '@/components/resource-table'
@@ -197,10 +198,15 @@ export default function Sessions() {
htmlFor="start-message"
description="What should the agent do? (required)"
>
- <Textarea
+ <ChatTextarea
id="start-message"
value={message}
onChange={(e) => setMessage(e.target.value)}
+ onSend={() => {
+ if (agentId && message.trim() && !startMutation.isPending) {
+ startMutation.mutate()
+ }
+ }}
placeholder="Review PR #412 and open a follow-up if anything needs fixing."
className="min-h-24"
/>