fix(hashline-edit): restore leading indentation for first line in replace_lines
- BUG-21: Apply restoreLeadingIndent to first entry of replace_lines, matching set_line behavior - Update test to verify indentation preservation
This commit is contained in:
@@ -128,7 +128,7 @@ describe("hashline edit operations", () => {
|
|||||||
expect(result).toEqual(["before", "new 1", "new 2", "after"])
|
expect(result).toEqual(["before", "new 1", "new 2", "after"])
|
||||||
})
|
})
|
||||||
|
|
||||||
it("does not restore indentation for replace_lines", () => {
|
it("restores indentation for first replace_lines entry", () => {
|
||||||
//#given
|
//#given
|
||||||
const lines = ["if (x) {", " return 1", " return 2", "}"]
|
const lines = ["if (x) {", " return 1", " return 2", "}"]
|
||||||
|
|
||||||
@@ -136,6 +136,6 @@ describe("hashline edit operations", () => {
|
|||||||
const result = applyReplaceLines(lines, anchorFor(lines, 2), anchorFor(lines, 3), ["return 3", "return 4"])
|
const result = applyReplaceLines(lines, anchorFor(lines, 2), anchorFor(lines, 3), ["return 3", "return 4"])
|
||||||
|
|
||||||
//#then
|
//#then
|
||||||
expect(result).toEqual(["if (x) {", "return 3", "return 4", "}"])
|
expect(result).toEqual(["if (x) {", " return 3", "return 4", "}"])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -124,7 +124,11 @@ export function applyReplaceLines(
|
|||||||
|
|
||||||
const result = [...lines]
|
const result = [...lines]
|
||||||
const stripped = stripRangeBoundaryEcho(lines, startLine, endLine, toNewLines(newText))
|
const stripped = stripRangeBoundaryEcho(lines, startLine, endLine, toNewLines(newText))
|
||||||
result.splice(startLine - 1, endLine - startLine + 1, ...stripped)
|
const restored = stripped.map((entry, idx) => {
|
||||||
|
if (idx !== 0) return entry
|
||||||
|
return restoreLeadingIndent(lines[startLine - 1], entry)
|
||||||
|
})
|
||||||
|
result.splice(startLine - 1, endLine - startLine + 1, ...restored)
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user