Merge pull request #2003 from code-yeongyu/fix/bug-21-indent-restore

fix(hashline-edit): restore leading indentation for first line in replace_lines
This commit is contained in:
YeonGyu-Kim 2026-02-21 02:41:33 +09:00 committed by GitHub
commit 21850face7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 3 deletions

View File

@ -128,7 +128,7 @@ describe("hashline edit operations", () => {
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
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"])
//#then
expect(result).toEqual(["if (x) {", "return 3", "return 4", "}"])
expect(result).toEqual(["if (x) {", " return 3", "return 4", "}"])
})
})

View File

@ -124,7 +124,11 @@ export function applyReplaceLines(
const result = [...lines]
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
}