Skip to content

Commit 2ffb009

Browse files
committed
Speed up diff edits
1 parent f47dd2d commit 2ffb009

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

.changeset/smooth-jokes-hammer.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"roo-cline": patch
3+
---
4+
5+
Speed up diff editing (thanks @hannesrudolph!)

src/integrations/editor/DiffViewProvider.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ export class DiffViewProvider {
8888
if (!isFinal) {
8989
accumulatedLines.pop() // remove the last partial line only if it's not the final update
9090
}
91-
const diffLines = accumulatedLines.slice(this.streamedLines.length)
9291

9392
const diffEditor = this.activeDiffEditor
9493
const document = diffEditor?.document
@@ -100,21 +99,19 @@ export class DiffViewProvider {
10099
const beginningOfDocument = new vscode.Position(0, 0)
101100
diffEditor.selection = new vscode.Selection(beginningOfDocument, beginningOfDocument)
102101

103-
for (let i = 0; i < diffLines.length; i++) {
104-
const currentLine = this.streamedLines.length + i
105-
// Replace all content up to the current line with accumulated lines
106-
// This is necessary (as compared to inserting one line at a time) to handle cases where html tags on previous lines are auto closed for example
107-
const edit = new vscode.WorkspaceEdit()
108-
const rangeToReplace = new vscode.Range(0, 0, currentLine + 1, 0)
109-
const contentToReplace = accumulatedLines.slice(0, currentLine + 1).join("\n") + "\n"
110-
edit.replace(document.uri, rangeToReplace, contentToReplace)
111-
await vscode.workspace.applyEdit(edit)
112-
// Update decorations
113-
this.activeLineController.setActiveLine(currentLine)
114-
this.fadedOverlayController.updateOverlayAfterLine(currentLine, document.lineCount)
115-
// Scroll to the current line
116-
this.scrollEditorToLine(currentLine)
117-
}
102+
const endLine = accumulatedLines.length
103+
// Replace all content up to the current line with accumulated lines
104+
const edit = new vscode.WorkspaceEdit()
105+
const rangeToReplace = new vscode.Range(0, 0, endLine + 1, 0)
106+
const contentToReplace = accumulatedLines.slice(0, endLine + 1).join("\n") + "\n"
107+
edit.replace(document.uri, rangeToReplace, contentToReplace)
108+
await vscode.workspace.applyEdit(edit)
109+
// Update decorations
110+
this.activeLineController.setActiveLine(endLine)
111+
this.fadedOverlayController.updateOverlayAfterLine(endLine, document.lineCount)
112+
// Scroll to the current line
113+
this.scrollEditorToLine(endLine)
114+
118115
// Update the streamedLines with the new accumulated content
119116
this.streamedLines = accumulatedLines
120117
if (isFinal) {

0 commit comments

Comments
 (0)