Compare commits

...

2 Commits

Author SHA1 Message Date
Elephant Lumps 7f4d08f4a5 changeset 2025-05-07 00:15:41 -05:00
Elephant Lumps 58bf429790 disable auto scroll on user scroll up 2025-05-07 00:14:49 -05:00
2 changed files with 57 additions and 17 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"claude-dev": minor
---
Allow the user to scroll when Cline is editing a file by disabling auto-scroll when the user scrolls up
+52 -17
View File
@@ -26,6 +26,9 @@ export class DiffViewProvider {
private streamedLines: string[] = []
private preDiagnostics: [vscode.Uri, vscode.Diagnostic[]][] = []
private fileEncoding: string = "utf8"
private lastFirstVisibleLine: number = 0
private shouldAutoScroll: boolean = true
private scrollListener?: vscode.Disposable
constructor(private cwd: string) {}
@@ -34,6 +37,8 @@ export class DiffViewProvider {
const fileExists = this.editType === "modify"
const absolutePath = path.resolve(this.cwd, relPath)
this.isEditing = true
this.shouldAutoScroll = true
this.lastFirstVisibleLine = 0
// if the file is already open, ensure it's not dirty before getting its contents
if (fileExists) {
const existingDocument = vscode.workspace.textDocuments.find((doc) => arePathsEqual(doc.uri.fsPath, absolutePath))
@@ -79,6 +84,21 @@ export class DiffViewProvider {
this.fadedOverlayController.addLines(0, this.activeDiffEditor.document.lineCount)
this.scrollEditorToLine(0) // will this crash for new files?
this.streamedLines = []
// Add scroll detection to disable auto-scrolling when user scrolls up
this.scrollListener = vscode.window.onDidChangeTextEditorVisibleRanges((e: vscode.TextEditorVisibleRangesChangeEvent) => {
if (e.textEditor === this.activeDiffEditor) {
const currentFirstVisibleLine = e.visibleRanges[0]?.start.line || 0
// If the first visible line moved upward, user scrolled up
if (currentFirstVisibleLine < this.lastFirstVisibleLine) {
this.shouldAutoScroll = false
}
// Always update our tracking variable
this.lastFirstVisibleLine = currentFirstVisibleLine
}
})
}
async update(accumulatedContent: string, isFinal: boolean) {
@@ -128,25 +148,30 @@ export class DiffViewProvider {
this.activeLineController.setActiveLine(currentLine)
this.fadedOverlayController.updateOverlayAfterLine(currentLine, document.lineCount)
// Scroll to the last changed line
if (diffLines.length <= 5) {
// For small changes, just jump directly to the line
this.scrollEditorToLine(currentLine)
} else {
// For larger changes, create a quick scrolling animation
const startLine = this.streamedLines.length
const endLine = currentLine
const totalLines = endLine - startLine
const numSteps = 10 // Adjust this number to control animation speed
const stepSize = Math.max(1, Math.floor(totalLines / numSteps))
// Scroll to the last changed line only if the user hasn't scrolled up
if (this.shouldAutoScroll) {
if (diffLines.length <= 5) {
// For small changes, just jump directly to the line
this.scrollEditorToLine(currentLine)
} else {
// For larger changes, create a quick scrolling animation
const startLine = this.streamedLines.length
const endLine = currentLine
const totalLines = endLine - startLine
const numSteps = 10 // Adjust this number to control animation speed
const stepSize = Math.max(1, Math.floor(totalLines / numSteps))
// Create and await the smooth scrolling animation
for (let line = startLine; line <= endLine; line += stepSize) {
this.activeDiffEditor?.revealRange(new vscode.Range(line, 0, line, 0), vscode.TextEditorRevealType.InCenter)
await new Promise((resolve) => setTimeout(resolve, 16)) // ~60fps
// Create and await the smooth scrolling animation
for (let line = startLine; line <= endLine; line += stepSize) {
this.activeDiffEditor?.revealRange(
new vscode.Range(line, 0, line, 0),
vscode.TextEditorRevealType.InCenter,
)
await new Promise((resolve) => setTimeout(resolve, 16)) // ~60fps
}
// Ensure we end at the final line
this.scrollEditorToLine(currentLine)
}
// Ensure we end at the final line
this.scrollEditorToLine(currentLine)
}
}
@@ -418,5 +443,15 @@ export class DiffViewProvider {
this.activeLineController = undefined
this.streamedLines = []
this.preDiagnostics = []
// Clean up the scroll listener
if (this.scrollListener) {
this.scrollListener.dispose()
this.scrollListener = undefined
}
// Reset auto-scroll state
this.shouldAutoScroll = true
this.lastFirstVisibleLine = 0
}
}