Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/core/diff/strategies/__tests__/multi-search-replace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2332,6 +2332,54 @@ function two() {
function three() {
return "three";
}`)
}
})

it("should deduce start_line when include line number in search and replace content", async () => {
const originalContent = `
function one() {
return 1;
}
function process() {
return "target";
}
function process() {
return "target";
}
function two() {
return 2;
}
`.trim()
const diffContent = `test.ts
<<<<<<< SEARCH
9 | function process() {
10 | return "target";
=======
9 | function process2() {
10 | return "target222";
>>>>>>> REPLACE`

const result = await strategy.applyDiff(originalContent, diffContent)
expect(result.success).toBe(true)
if (result.success) {
expect(result.content).toBe(`function one() {
return 1;
}
function process() {
return "target";
}
function process2() {
return "target222";
}
function two() {
return 2;
}`)
}
})
Expand Down
4 changes: 4 additions & 0 deletions src/core/diff/strategies/multi-search-replace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,10 @@ Only use a single line of '=======' between search and replacement content, beca
(everyLineHasLineNumbers(searchContent) && everyLineHasLineNumbers(replaceContent)) ||
(everyLineHasLineNumbers(searchContent) && replaceContent.trim() === "")

if (hasAllLineNumbers && startLine === 0) {
startLine = parseInt(searchContent.split("\n")[0].split("|")[0])
}

if (hasAllLineNumbers) {
searchContent = stripLineNumbers(searchContent)
replaceContent = stripLineNumbers(replaceContent)
Expand Down