mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-20 04:11:10 -05:00
Negative indentation
This commit is contained in:
@@ -416,6 +416,93 @@ class Example {
|
|||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle negative indentation relative to search content', () => {
|
||||||
|
const originalContent = `class Example {
|
||||||
|
constructor() {
|
||||||
|
if (true) {
|
||||||
|
this.init();
|
||||||
|
this.setup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`.trim();
|
||||||
|
const diffContent = `test.ts
|
||||||
|
<<<<<<< SEARCH
|
||||||
|
this.init();
|
||||||
|
this.setup();
|
||||||
|
=======
|
||||||
|
this.init();
|
||||||
|
this.setup();
|
||||||
|
>>>>>>> REPLACE`;
|
||||||
|
|
||||||
|
const result = strategy.applyDiff(originalContent, diffContent);
|
||||||
|
expect(result).toBe(`class Example {
|
||||||
|
constructor() {
|
||||||
|
if (true) {
|
||||||
|
this.init();
|
||||||
|
this.setup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle extreme negative indentation (no indent)', () => {
|
||||||
|
const originalContent = `class Example {
|
||||||
|
constructor() {
|
||||||
|
if (true) {
|
||||||
|
this.init();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`.trim();
|
||||||
|
const diffContent = `test.ts
|
||||||
|
<<<<<<< SEARCH
|
||||||
|
this.init();
|
||||||
|
=======
|
||||||
|
this.init();
|
||||||
|
>>>>>>> REPLACE`;
|
||||||
|
|
||||||
|
const result = strategy.applyDiff(originalContent, diffContent);
|
||||||
|
expect(result).toBe(`class Example {
|
||||||
|
constructor() {
|
||||||
|
if (true) {
|
||||||
|
this.init();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle mixed indentation changes in replace block', () => {
|
||||||
|
const originalContent = `class Example {
|
||||||
|
constructor() {
|
||||||
|
if (true) {
|
||||||
|
this.init();
|
||||||
|
this.setup();
|
||||||
|
this.validate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`.trim();
|
||||||
|
const diffContent = `test.ts
|
||||||
|
<<<<<<< SEARCH
|
||||||
|
this.init();
|
||||||
|
this.setup();
|
||||||
|
this.validate();
|
||||||
|
=======
|
||||||
|
this.init();
|
||||||
|
this.setup();
|
||||||
|
this.validate();
|
||||||
|
>>>>>>> REPLACE`;
|
||||||
|
|
||||||
|
const result = strategy.applyDiff(originalContent, diffContent);
|
||||||
|
expect(result).toBe(`class Example {
|
||||||
|
constructor() {
|
||||||
|
if (true) {
|
||||||
|
this.init();
|
||||||
|
this.setup();
|
||||||
|
this.validate();
|
||||||
|
}
|
||||||
|
}
|
||||||
}`);
|
}`);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -211,11 +211,18 @@ Your search/replace content here
|
|||||||
const currentIndent = currentIndentMatch ? currentIndentMatch[0] : '';
|
const currentIndent = currentIndentMatch ? currentIndentMatch[0] : '';
|
||||||
const searchBaseIndent = searchIndents[0] || '';
|
const searchBaseIndent = searchIndents[0] || '';
|
||||||
|
|
||||||
// Calculate the relative indentation from the search content
|
// Calculate the relative indentation level
|
||||||
const relativeIndent = currentIndent.slice(searchBaseIndent.length);
|
const searchBaseLevel = searchBaseIndent.length;
|
||||||
|
const currentLevel = currentIndent.length;
|
||||||
|
const relativeLevel = currentLevel - searchBaseLevel;
|
||||||
|
|
||||||
// Apply the matched indentation plus any relative indentation
|
// If relative level is negative, remove indentation from matched indent
|
||||||
return matchedIndent + relativeIndent + line.trim();
|
// If positive, add to matched indent
|
||||||
|
const finalIndent = relativeLevel < 0
|
||||||
|
? matchedIndent.slice(0, Math.max(0, matchedIndent.length + relativeLevel))
|
||||||
|
: matchedIndent + currentIndent.slice(searchBaseLevel);
|
||||||
|
|
||||||
|
return finalIndent + line.trim();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Construct the final content
|
// Construct the final content
|
||||||
|
|||||||
Reference in New Issue
Block a user