11import { useCallback , useState } from "react"
22import type { HistoryItem } from "@roo-code/types"
33
4- import { Input } from "@/components/ui"
4+ import { AutosizeTextarea } from "@/components/ui"
55import { useAppTranslation } from "@/i18n/TranslationContext"
66import { cn } from "@/lib/utils"
77import { vscode } from "@/utils/vscode"
@@ -14,17 +14,22 @@ type TaskTitleEditorProps = {
1414 className ?: string
1515}
1616
17+ // Titles are a single line: line breaks and repeated whitespace collapse to one space.
18+ const normalizeTitle = ( text : string ) => text . replace ( / \s + / g, " " ) . trim ( )
19+
1720/**
18- * Inline input for renaming a history item. Enter saves, Escape or blur cancels.
21+ * Inline editor for renaming a history item. Enter saves, Escape or blur cancels.
1922 * Saving a blank value, or the original prompt, clears the custom title.
23+ *
24+ * It wraps instead of scrolling sideways so a long title stays readable at narrow widths.
2025 */
2126export const TaskTitleEditor = ( { item, onDone, className } : TaskTitleEditorProps ) => {
2227 const { t } = useAppTranslation ( )
23- const [ value , setValue ] = useState ( ( ) => getTaskDisplayTitle ( item ) )
28+ const [ value , setValue ] = useState ( ( ) => normalizeTitle ( getTaskDisplayTitle ( item ) ) )
2429
2530 const save = useCallback ( ( ) => {
26- const trimmed = value . trim ( )
27- const nextTitle = trimmed && trimmed !== item . task . trim ( ) ? trimmed : undefined
31+ const normalized = normalizeTitle ( value )
32+ const nextTitle = normalized && normalized !== normalizeTitle ( item . task ) ? normalized : undefined
2833
2934 if ( nextTitle !== item . title ) {
3035 vscode . postMessage ( { type : "renameTaskWithId" , taskId : item . id , text : nextTitle ?? "" } )
@@ -36,8 +41,12 @@ export const TaskTitleEditor = ({ item, onDone, className }: TaskTitleEditorProp
3641 // Let keydown keep bubbling: VS Code's webview host listens on `window` to run
3742 // clipboard and undo shortcuts, so stopping propagation breaks paste (Cmd/Ctrl+V).
3843 const handleKeyDown = useCallback (
39- ( e : React . KeyboardEvent < HTMLInputElement > ) => {
44+ ( e : React . KeyboardEvent < HTMLTextAreaElement > ) => {
4045 if ( e . key === "Enter" ) {
46+ // IME users press Enter to confirm a conversion candidate, not to save.
47+ if ( e . nativeEvent . isComposing || e . keyCode === 229 ) {
48+ return
49+ }
4150 e . preventDefault ( )
4251 save ( )
4352 } else if ( e . key === "Escape" ) {
@@ -49,18 +58,24 @@ export const TaskTitleEditor = ({ item, onDone, className }: TaskTitleEditorProp
4958 )
5059
5160 return (
52- < Input
61+ < AutosizeTextarea
5362 data-testid = "task-title-input"
5463 aria-label = { t ( "history:renameTask" ) }
55- placeholder = { item . task }
64+ placeholder = { normalizeTitle ( item . task ) }
5665 value = { value }
66+ rows = { 1 }
67+ minHeight = { 20 }
68+ maxHeight = { 120 }
5769 autoFocus
5870 onFocus = { ( e ) => e . currentTarget . select ( ) }
5971 onChange = { ( e ) => setValue ( e . target . value ) }
6072 onKeyDown = { handleKeyDown }
6173 onBlur = { onDone }
6274 onClick = { ( e ) => e . stopPropagation ( ) }
63- className = { cn ( "flex-1 min-w-0 text-base rounded-md select-text" , className ) }
75+ className = { cn (
76+ "flex-1 min-w-0 resize-none border rounded-md px-2 py-1 text-base select-text break-words" ,
77+ className ,
78+ ) }
6479 />
6580 )
6681}
0 commit comments