mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-07-22 07:41:23 -07:00
Fixes.
This commit is contained in:
@@ -415,6 +415,9 @@ describe('EditTool', () => {
|
|||||||
{ start: 2, end: 3 },
|
{ start: 2, end: 3 },
|
||||||
{ start: 5, end: 6 },
|
{ start: 5, end: 6 },
|
||||||
]);
|
]);
|
||||||
|
expect(result.newContent).toBe(
|
||||||
|
' line1\n replacement\n line3\n replacement\n line5',
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should correctly calculate matchRanges for regex replacements', async () => {
|
it('should correctly calculate matchRanges for regex replacements', async () => {
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ async function calculateFlexibleReplacement(
|
|||||||
|
|
||||||
let flexibleOccurrences = 0;
|
let flexibleOccurrences = 0;
|
||||||
const matchRanges: Array<{ start: number; end: number }> = [];
|
const matchRanges: Array<{ start: number; end: number }> = [];
|
||||||
let lineOffset = 0;
|
let currentOriginalLine = 1;
|
||||||
let i = 0;
|
let i = 0;
|
||||||
while (i <= sourceLines.length - searchLinesStripped.length) {
|
while (i <= sourceLines.length - searchLinesStripped.length) {
|
||||||
const window = sourceLines.slice(i, i + searchLinesStripped.length);
|
const window = sourceLines.slice(i, i + searchLinesStripped.length);
|
||||||
@@ -241,21 +241,24 @@ async function calculateFlexibleReplacement(
|
|||||||
if (isMatch) {
|
if (isMatch) {
|
||||||
flexibleOccurrences++;
|
flexibleOccurrences++;
|
||||||
matchRanges.push({
|
matchRanges.push({
|
||||||
start: i + 1 - lineOffset,
|
start: currentOriginalLine,
|
||||||
end: i + searchLinesStripped.length - lineOffset,
|
end: currentOriginalLine + searchLinesStripped.length - 1,
|
||||||
});
|
});
|
||||||
const firstLineInMatch = window[0];
|
const firstLineInMatch = window[0];
|
||||||
const indentationMatch = firstLineInMatch.match(/^([ \t]*)/);
|
const indentationMatch = firstLineInMatch.match(/^([ \t]*)/);
|
||||||
const indentation = indentationMatch ? indentationMatch[1] : '';
|
const indentation = indentationMatch ? indentationMatch[1] : '';
|
||||||
const newBlockWithIndent = applyIndentation(replaceLines, indentation);
|
const newBlockWithIndent = applyIndentation(replaceLines, indentation);
|
||||||
sourceLines.splice(
|
|
||||||
i,
|
let replacementText = newBlockWithIndent.join('\n');
|
||||||
searchLinesStripped.length,
|
if (window[window.length - 1].endsWith('\n')) {
|
||||||
newBlockWithIndent.join('\n'),
|
replacementText += '\n';
|
||||||
);
|
}
|
||||||
lineOffset += replaceLines.length - searchLinesStripped.length;
|
|
||||||
i += replaceLines.length;
|
sourceLines.splice(i, searchLinesStripped.length, replacementText);
|
||||||
|
currentOriginalLine += searchLinesStripped.length;
|
||||||
|
i++;
|
||||||
} else {
|
} else {
|
||||||
|
currentOriginalLine++;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user