-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat: add setting to auto-expand diffs in chat messages #11316
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -97,6 +97,7 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro | |
| messageQueue = [], | ||
| isBrowserSessionActive, | ||
| showWorktreesInHomeScreen, | ||
| autoExpandDiffs, | ||
| } = useExtensionState() | ||
|
|
||
| const messagesRef = useRef(messages) | ||
|
|
@@ -527,6 +528,43 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro | |
| prevExpandedRowsRef.current = expandedRows // Store current state for next comparison | ||
| }, [expandedRows]) | ||
|
|
||
| // Auto-expand diff rows when autoExpandDiffs setting is enabled | ||
| const DIFF_TOOL_TYPES = useMemo( | ||
| () => new Set(["editedExistingFile", "appliedDiff", "insertContent", "searchAndReplace", "newFileCreated"]), | ||
| [], | ||
| ) | ||
|
|
||
| useEffect(() => { | ||
| if (!autoExpandDiffs) { | ||
| return | ||
| } | ||
|
|
||
| const newExpansions: Record<number, boolean> = {} | ||
|
|
||
| for (const msg of modifiedMessages) { | ||
| // Skip messages already tracked in expandedRows | ||
| if (expandedRows[msg.ts] !== undefined) { | ||
| continue | ||
| } | ||
|
|
||
| // Check if this message contains a diff tool | ||
| if (msg.text) { | ||
| try { | ||
| const tool = JSON.parse(msg.text) | ||
| if (tool.tool && DIFF_TOOL_TYPES.has(tool.tool)) { | ||
| newExpansions[msg.ts] = true | ||
| } | ||
| } catch { | ||
| // Not valid JSON, skip | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (Object.keys(newExpansions).length > 0) { | ||
| setExpandedRows((prev) => ({ ...prev, ...newExpansions })) | ||
| } | ||
| }, [modifiedMessages, autoExpandDiffs, expandedRows, DIFF_TOOL_TYPES]) | ||
|
Comment on lines
+537
to
+566
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. When this effect auto-expands diffs via Fix it with Roo Code or mention @roomote and request a fix. |
||
|
|
||
| const isStreaming = useMemo(() => { | ||
| // Checking clineAsk isn't enough since messages effect may be called | ||
| // again for a tool for example, set clineAsk to its value, and if the | ||
|
|
||
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.
Including
expandedRowsin the dependency array here means this effect re-runs on every expansion/collapse (user or auto), iterating allmodifiedMessagesandJSON.parse-ing each one. It also causes a double execution when it auto-expands: thesetExpandedRowscall updatesexpandedRows, which re-triggers the effect (the second run is a no-op but still wasteful). You can fix both problems by moving the logic into the functional updater ofsetExpandedRowsand droppingexpandedRowsfrom deps:Fix it with Roo Code or mention @roomote and request a fix.