From 0832505e131a84da6a1e9c112580be285c00fa2b Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Fri, 20 Feb 2026 17:47:37 +0900 Subject: [PATCH] fix(hashline-edit): do not restore indentation for replace_lines MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - applyReplaceLines: use stripped array directly instead of restoreLeadingIndent - applySetLine: keep restoreLeadingIndent (1:1 replacement needs indent preservation) - Added test case for replace_lines preserving new line indentation - All 3025 tests pass 🤖 Generated with OhMyOpenCode assistance --- src/tools/hashline-edit/edit-operations.test.ts | 11 +++++++++++ src/tools/hashline-edit/edit-operations.ts | 7 +------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/tools/hashline-edit/edit-operations.test.ts b/src/tools/hashline-edit/edit-operations.test.ts index 45abaa4c..40c2a36d 100644 --- a/src/tools/hashline-edit/edit-operations.test.ts +++ b/src/tools/hashline-edit/edit-operations.test.ts @@ -127,4 +127,15 @@ describe("hashline edit operations", () => { //#then expect(result).toEqual(["before", "new 1", "new 2", "after"]) }) + + it("does not restore indentation for replace_lines", () => { + //#given + const lines = ["if (x) {", " return 1", " return 2", "}"] + + //#when + const result = applyReplaceLines(lines, anchorFor(lines, 2), anchorFor(lines, 3), ["return 3", "return 4"]) + + //#then + expect(result).toEqual(["if (x) {", "return 3", "return 4", "}"]) + }) }) diff --git a/src/tools/hashline-edit/edit-operations.ts b/src/tools/hashline-edit/edit-operations.ts index 9929e9ac..df31d997 100644 --- a/src/tools/hashline-edit/edit-operations.ts +++ b/src/tools/hashline-edit/edit-operations.ts @@ -124,12 +124,7 @@ export function applyReplaceLines( const result = [...lines] const stripped = stripRangeBoundaryEcho(lines, startLine, endLine, toNewLines(newText)) - const newLines = stripped.map((entry, idx) => { - const oldLine = lines[startLine - 1 + idx] - if (!oldLine) return entry - return restoreLeadingIndent(oldLine, entry) - }) - result.splice(startLine - 1, endLine - startLine + 1, ...newLines) + result.splice(startLine - 1, endLine - startLine + 1, ...stripped) return result }