Skip to content

Commit 28cf54b

Browse files
committed
feat: auto-scroll to edit location after user edits in diff view
- Added ref to user_feedback_diff element - Implemented smooth scroll behavior when user edits appear - Scrolls to center of viewport for better visibility Fixes #7996
1 parent 9d33c10 commit 28cf54b

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ export const ChatRowContent = ({
125125
const [editMode, setEditMode] = useState<Mode>(mode || "code")
126126
const [editImages, setEditImages] = useState<string[]>([])
127127
const { copyWithFeedback } = useCopyToClipboard()
128+
const userEditRef = useRef<HTMLDivElement>(null)
128129

129130
// Handle message events for image selection during edit mode
130131
useEffect(() => {
@@ -351,6 +352,22 @@ export const ChatRowContent = ({
351352
return null
352353
}, [message.type, message.ask, message.partial, message.text])
353354

355+
// Scroll to user edits when they appear
356+
useEffect(() => {
357+
if (message.say === "user_feedback_diff" && userEditRef.current) {
358+
const tool = safeJsonParse<ClineSayTool>(message.text)
359+
if (tool?.diff) {
360+
// Use a small delay to ensure the element is rendered
361+
setTimeout(() => {
362+
userEditRef.current?.scrollIntoView({
363+
behavior: "smooth",
364+
block: "center",
365+
})
366+
}, 100)
367+
}
368+
}
369+
}, [message.say, message.text])
370+
354371
if (tool) {
355372
const toolIcon = (name: string) => (
356373
<span
@@ -1241,7 +1258,7 @@ export const ChatRowContent = ({
12411258
case "user_feedback_diff":
12421259
const tool = safeJsonParse<ClineSayTool>(message.text)
12431260
return (
1244-
<div style={{ marginTop: -10, width: "100%" }}>
1261+
<div ref={userEditRef} style={{ marginTop: -10, width: "100%" }}>
12451262
<CodeAccordian
12461263
code={tool?.diff}
12471264
language="diff"

0 commit comments

Comments
 (0)