diff --git a/src/tools/hashline-edit/autocorrect-replacement-lines.ts b/src/tools/hashline-edit/autocorrect-replacement-lines.ts index 6b9d9a77..719f9d6c 100644 --- a/src/tools/hashline-edit/autocorrect-replacement-lines.ts +++ b/src/tools/hashline-edit/autocorrect-replacement-lines.ts @@ -159,6 +159,7 @@ export function restoreIndentForPairedReplacement( if (leadingWhitespace(line).length > 0) return line const indent = leadingWhitespace(originalLines[idx]) if (indent.length === 0) return line + if (originalLines[idx].trim() === line.trim()) return line return `${indent}${line}` }) } diff --git a/src/tools/hashline-edit/edit-operations.test.ts b/src/tools/hashline-edit/edit-operations.test.ts index 53910660..d66c2d94 100644 --- a/src/tools/hashline-edit/edit-operations.test.ts +++ b/src/tools/hashline-edit/edit-operations.test.ts @@ -177,6 +177,28 @@ describe("hashline edit operations", () => { expect(result).toEqual(["if (x) {", " return 2", "}"]) }) + it("preserves intentional indentation removal (tab to no-tab)", () => { + //#given + const lines = ["# Title", "\t1절", "content"] + + //#when + const result = applySetLine(lines, anchorFor(lines, 2), "1절") + + //#then + expect(result).toEqual(["# Title", "1절", "content"]) + }) + + it("preserves intentional indentation removal (spaces to no-spaces)", () => { + //#given + const lines = ["function foo() {", " indented", "}"] + + //#when + const result = applySetLine(lines, anchorFor(lines, 2), "indented") + + //#then + expect(result).toEqual(["function foo() {", "indented", "}"]) + }) + it("strips boundary echo around replace_lines content", () => { //#given const lines = ["before", "old 1", "old 2", "after"] diff --git a/src/tools/hashline-edit/edit-text-normalization.ts b/src/tools/hashline-edit/edit-text-normalization.ts index 8e38c50c..9bae8cc4 100644 --- a/src/tools/hashline-edit/edit-text-normalization.ts +++ b/src/tools/hashline-edit/edit-text-normalization.ts @@ -53,6 +53,7 @@ export function restoreLeadingIndent(templateLine: string, line: string): string const templateIndent = leadingWhitespace(templateLine) if (templateIndent.length === 0) return line if (leadingWhitespace(line).length > 0) return line + if (templateLine.trim() === line.trim()) return line return `${templateIndent}${line}` }