Use diff to find first changed block

This commit is contained in:
Saoud Rizwan
2024-09-10 21:46:03 -04:00
parent 83b813ab2a
commit 74ac4a69aa
2 changed files with 14 additions and 19 deletions

View File

@@ -847,26 +847,21 @@ export class ClaudeDev {
// Apply the edit, but without saving so this doesnt trigger a local save in timeline history // Apply the edit, but without saving so this doesnt trigger a local save in timeline history
await vscode.workspace.applyEdit(edit) // has the added benefit of maintaing the file's original EOLs await vscode.workspace.applyEdit(edit) // has the added benefit of maintaing the file's original EOLs
// Find the first position where the content differs and scroll to the first changed line if found // Find the first range where the content differs and scroll to it
let firstDiffPosition: vscode.Position | undefined const diffResult = diff.diffLines(originalContent, newContent)
const originalLines = originalContent.split("\n") for (let i = 0, lineCount = 0; i < diffResult.length; i++) {
const newLines = newContent.split("\n") const part = diffResult[i]
for (let i = 0; i < Math.max(originalLines.length, newLines.length); i++) { if (part.added || part.removed) {
if (i < originalLines.length && i < newLines.length) { const startLine = lineCount + 1
if (originalLines[i] !== newLines[i]) { const endLine = lineCount + (part.count || 0)
firstDiffPosition = new vscode.Position(i, 0) vscode.window.activeTextEditor?.revealRange(
break // + 3 to move the editor up slightly as this looks better
} new vscode.Range(new vscode.Position(startLine, 0), new vscode.Position(endLine + 3, 0)),
} else { vscode.TextEditorRevealType.InCenter
firstDiffPosition = new vscode.Position(i, 0) )
break break
} }
} lineCount += part.count || 0
if (firstDiffPosition) {
vscode.window.activeTextEditor?.revealRange(
new vscode.Range(firstDiffPosition, firstDiffPosition),
vscode.TextEditorRevealType.InCenter
)
} }
// remove cursor from the document // remove cursor from the document

View File

@@ -607,7 +607,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
// borderLeft: "9px solid transparent", // NOTE: react-textarea-autosize doesn't calculate correct height when using borderLeft/borderRight so we need to use horizontal padding instead // borderLeft: "9px solid transparent", // NOTE: react-textarea-autosize doesn't calculate correct height when using borderLeft/borderRight so we need to use horizontal padding instead
// Instead of using boxShadow, we use a div with a border to better replicate the behavior when the textarea is focused // Instead of using boxShadow, we use a div with a border to better replicate the behavior when the textarea is focused
// boxShadow: "0px 0px 0px 1px var(--vscode-input-border)", // boxShadow: "0px 0px 0px 1px var(--vscode-input-border)",
padding: "0 50px 0 9px", padding: "0 53px 0 9px",
cursor: textAreaDisabled ? "not-allowed" : undefined, cursor: textAreaDisabled ? "not-allowed" : undefined,
flex: 1, flex: 1,
}} }}