Skip to content

Commit b28edab

Browse files
committed
fix: scroll to edit area when editing long historical messages
- Added ref to track edit area element - Added useEffect to scroll into view when entering edit mode - Uses smooth scrolling with center block positioning for better UX Fixes #8724
1 parent a8f87d2 commit b28edab

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

webview-ui/src/components/chat/ChatRow.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ export const ChatRowContent = ({
136136
const [editedContent, setEditedContent] = useState("")
137137
const [editMode, setEditMode] = useState<Mode>(mode || "code")
138138
const [editImages, setEditImages] = useState<string[]>([])
139+
const editAreaRef = useRef<HTMLDivElement>(null)
139140

140141
// Handle message events for image selection during edit mode
141142
useEffect(() => {
@@ -165,6 +166,19 @@ export const ChatRowContent = ({
165166
// No need to notify the backend
166167
}, [message.text, message.images, mode])
167168

169+
// Scroll to edit area when entering edit mode
170+
useEffect(() => {
171+
if (isEditing && editAreaRef.current) {
172+
// Use a small delay to ensure the DOM has updated
173+
setTimeout(() => {
174+
editAreaRef.current?.scrollIntoView({
175+
behavior: "smooth",
176+
block: "center",
177+
})
178+
}, 100)
179+
}
180+
}, [isEditing])
181+
168182
// Handle cancel edit
169183
const handleCancelEdit = useCallback(() => {
170184
setIsEditing(false)
@@ -1110,6 +1124,7 @@ export const ChatRowContent = ({
11101124
<span style={{ fontWeight: "bold" }}>{t("chat:feedback.youSaid")}</span>
11111125
</div>
11121126
<div
1127+
ref={editAreaRef}
11131128
className={cn(
11141129
"ml-6 border rounded-sm overflow-hidden whitespace-pre-wrap",
11151130
isEditing

0 commit comments

Comments
 (0)