Skip to content

Conversation

@j-east
Copy link

@j-east j-east commented Sep 15, 2025

Related GitHub Issue

Closes #7996

Description

This PR provides a straightforward way to focus the file and scroll to the user edits (if any). It does this by adding 2 new static class methods in EditorUtils. There is adequate error handling such that if there are errors (I could not get any errors to happen in testing) it is minimally impactful

Test Procedure

  1. With edit approval not set to auto approve, create a task and allow Roo Code to present some edits in the diff view.
  2. Make some changes while in the diff view (add a comment in the middle of the file for instance)
  3. Click Save
  4. Confirm that the file is now focused and the edits you made are now in view

Pre-Submission Checklist

  • [ X] Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • [X ] Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • [ X] Self-Review: I have performed a thorough self-review of my code.
  • [ X] Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

RooScrollToEdits.mov

Documentation Updates

Additional Notes

n/a

Get in Touch

jevons


Important

Adds feature to auto-scroll to user edits in a file using new methods in EditorUtils and integrates it into DiffViewProvider.

  • Behavior:
    • Adds openAndScrollToEdits() and extractFirstChangedLineFromDiff() methods in EditorUtils to open a file and scroll to the first user edit.
    • Integrates openAndScrollToEdits() in DiffViewProvider to focus and scroll to user edits after saving changes.
  • Error Handling:
    • Logs a warning if no changes are found in extractFirstChangedLineFromDiff() or if openAndScrollToEdits() fails.
  • Misc:

This description was created by Ellipsis for 7fe2585. You can customize this summary. It will automatically update as commits are pushed.

@j-east j-east requested review from cte, jr and mrubens as code owners September 15, 2025 19:00
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. enhancement New feature or request labels Sep 15, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Sep 15, 2025
Copy link
Contributor

@roomote roomote bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution! I've reviewed the changes and the implementation looks clean and addresses the issue well. I have some suggestions for improvement, particularly around test coverage and edge case handling.

* @param relPath Relative path to the file
* @param userEdits The diff content showing user edits
*/
static async openAndScrollToEdits(cwd: string, relPath: string, userEdits: string): Promise<void> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These new methods need test coverage. The existing test file at src/integrations/editor/__tests__/EditorUtils.spec.ts doesn't include tests for openAndScrollToEdits() and extractFirstChangedLineFromDiff(). Could you add tests to ensure these methods work correctly with various diff formats and edge cases?

viewColumn: vscode.ViewColumn.Active,
})
} catch (error) {
console.warn(`Failed to open and scroll to edits for ${relPath}:`, error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the silent failure intentional here? Users won't know if the scroll operation fails. Would it be better to provide some user feedback, perhaps through a notification or status bar message?

// Show the document with selection at the first changed line
const selection =
firstChangedLine !== null
? new vscode.Selection(Math.max(firstChangedLine - 1, 0), 0, Math.max(firstChangedLine - 1, 0), 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add validation to ensure the extracted line number is within the document bounds? If a diff has an invalid line number (e.g., line 1000 in a 100-line file), this could cause issues when trying to scroll to it.

Suggested change
? new vscode.Selection(Math.max(firstChangedLine - 1, 0), 0, Math.max(firstChangedLine - 1, 0), 0)
const firstChangedLine = this.extractFirstChangedLineFromDiff(userEdits)
if (!firstChangedLine) {
console.warn(`No changes found in user edits for ${relPath}`)
return
}
const document = await vscode.workspace.openTextDocument(fileUri)
// Validate line number is within document bounds
const validLine = Math.min(Math.max(firstChangedLine - 1, 0), document.lineCount - 1)
// Show the document with selection at the first changed line
const selection = new vscode.Selection(validLine, 0, validLine, 0)

}
}

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JSDoc could be more detailed about the expected diff format. Could you specify that this expects a unified diff format and what happens if no valid hunk headers are found?

await task.say("user_feedback_diff", JSON.stringify(say))

// Open and focus the file, scrolling to the first edited section
await EditorUtils.openAndScrollToEdits(cwd, this.relPath, this.userEdits)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to add a configuration option to enable/disable the auto-scroll behavior? Some users might prefer not to have their view automatically changed after saving edits.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it will be an issue. Reason being is that diff edits are not super common but when they do happen the user has already interrupted their workflow

@j-east
Copy link
Author

j-east commented Sep 15, 2025

I'm not sure why this is failing. Looks like a timeout idk. Please advise.

core/prompts/tests/custom-system-prompt.spec.ts > File-Based Custom System Prompt > should use default generation when no file-based system prompt is found
roo-cline:test: Error: Test timed out in 20000ms.
roo-cline:test: If this is a long-running test, pass a timeout value as the last argument or configure it globally with "testTimeout".
roo-cline:test: ❯ core/prompts/tests/custom-system-prompt.spec.ts:86:2
roo-cline:test: 84| })
roo-cline:test: 85|
roo-cline:test: 86| it("should use default generation when no file-based system prompt is…
roo-cline:test: | ^
roo-cline:test: 87| const customModePrompts = {
roo-cline:test: 88| [defaultModeSlug]: {
roo-cline:test:
roo-cline:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯
roo-cline:test:
roo-cline:test:
roo-cline:test: Test Files 1 failed | 292 passed | 3 skipped (296)
roo-cline:test: Tests 1 failed | 3813 passed | 41 skipped (3855)
roo-cline:test: Start at 19:04:29
roo-cline:test: Duration 244.89s (transform 28.32s, setup 40.40s, collect 157.04s, tests 319.85s, environment 199ms, prepare 98.15s)
roo-cline:test:
roo-cline:test:  ELIFECYCLE  Test failed. See above for more details.

@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Sep 15, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Sep 15, 2025
@daniel-lxs
Copy link
Member

After review and testing, we've determined that while the auto-scrolling feature is a nice quality-of-life improvement, it adds unnecessary complexity to the codebase for a relatively minor benefit. The current behavior where users can manually scroll to their edits is sufficient. Thank you for the contribution and the effort put into this implementation!

@daniel-lxs daniel-lxs closed this Sep 16, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Sep 16, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Prelim Review] to Done in Roo Code Roadmap Sep 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request PR - Needs Preliminary Review size:M This PR changes 30-99 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

File scroll to edit location after "User Edits" in diff.

3 participants