-
Notifications
You must be signed in to change notification settings - Fork 2.5k
feat: auto-scroll to edit location after user edits in diff view #7997
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -125,6 +125,7 @@ export const ChatRowContent = ({ | |||||||||||||||
| const [editMode, setEditMode] = useState<Mode>(mode || "code") | ||||||||||||||||
| const [editImages, setEditImages] = useState<string[]>([]) | ||||||||||||||||
| const { copyWithFeedback } = useCopyToClipboard() | ||||||||||||||||
| const userEditRef = useRef<HTMLDivElement>(null) | ||||||||||||||||
|
|
||||||||||||||||
| // Handle message events for image selection during edit mode | ||||||||||||||||
| useEffect(() => { | ||||||||||||||||
|
|
@@ -351,6 +352,22 @@ export const ChatRowContent = ({ | |||||||||||||||
| return null | ||||||||||||||||
| }, [message.type, message.ask, message.partial, message.text]) | ||||||||||||||||
|
|
||||||||||||||||
| // Scroll to user edits when they appear | ||||||||||||||||
| useEffect(() => { | ||||||||||||||||
| if (message.say === "user_feedback_diff" && userEditRef.current) { | ||||||||||||||||
| const tool = safeJsonParse<ClineSayTool>(message.text) | ||||||||||||||||
| if (tool?.diff) { | ||||||||||||||||
| // Use a small delay to ensure the element is rendered | ||||||||||||||||
| setTimeout(() => { | ||||||||||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor suggestion: Consider extracting this magic number to a named constant like |
||||||||||||||||
| userEditRef.current?.scrollIntoView({ | ||||||||||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this intentional? The code assumes
Suggested change
|
||||||||||||||||
| behavior: "smooth", | ||||||||||||||||
| block: "center", | ||||||||||||||||
| }) | ||||||||||||||||
| }, 100) | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
| }, [message.say, message.text]) | ||||||||||||||||
|
|
||||||||||||||||
| if (tool) { | ||||||||||||||||
| const toolIcon = (name: string) => ( | ||||||||||||||||
| <span | ||||||||||||||||
|
|
@@ -1241,7 +1258,7 @@ export const ChatRowContent = ({ | |||||||||||||||
| case "user_feedback_diff": | ||||||||||||||||
| const tool = safeJsonParse<ClineSayTool>(message.text) | ||||||||||||||||
| return ( | ||||||||||||||||
| <div style={{ marginTop: -10, width: "100%" }}> | ||||||||||||||||
| <div ref={userEditRef} style={{ marginTop: -10, width: "100%" }}> | ||||||||||||||||
| <CodeAccordian | ||||||||||||||||
| code={tool?.diff} | ||||||||||||||||
| language="diff" | ||||||||||||||||
|
|
||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we improve performance here? This useEffect runs on every render when
message.say === "user_feedback_diff". The tool is parsed twice - once in the condition check and once inside. Consider memoizing the parsed tool to avoid unnecessary JSON parsing on each render.