From b8af02ebaa69cbfb67aabed77f60ad68bef662e1 Mon Sep 17 00:00:00 2001 From: Evan <58194240+celestial-vault@users.noreply.github.com> Date: Wed, 7 May 2025 01:29:57 -0500 Subject: [PATCH] Stop doomscrolling (#3354) * disable auto scroll on user scroll up * changeset --------- Co-authored-by: Elephant Lumps --- .changeset/stupid-hotels-brush.md | 5 ++ src/integrations/editor/DiffViewProvider.ts | 69 ++++++++++++++++----- 2 files changed, 57 insertions(+), 17 deletions(-) create mode 100644 .changeset/stupid-hotels-brush.md diff --git a/.changeset/stupid-hotels-brush.md b/.changeset/stupid-hotels-brush.md new file mode 100644 index 00000000..0f13625d --- /dev/null +++ b/.changeset/stupid-hotels-brush.md @@ -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 diff --git a/src/integrations/editor/DiffViewProvider.ts b/src/integrations/editor/DiffViewProvider.ts index a6967e76..5e0e80b4 100644 --- a/src/integrations/editor/DiffViewProvider.ts +++ b/src/integrations/editor/DiffViewProvider.ts @@ -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 } }