Skip to content

Commit ba8bed9

Browse files
authored
Handle Windows line endings (#62)
1 parent 6e1f683 commit ba8bed9

File tree

7 files changed

+35
-11
lines changed

7 files changed

+35
-11
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Roo Cline Changelog
22

3+
## [2.1.18]
4+
5+
- Diff editing bugfix to handle Windows line endings
6+
37
## [2.1.17]
48

59
- Switch to search/replace diffs in experimental diff editing mode

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ A fork of Cline, an autonomous coding agent, with some added experimental config
77
- Unit test coverage (written almost entirely by Roo Cline!)
88
- Support for playing sound effects
99
- Support for OpenRouter compression
10-
- Support for editing through diffs (very experimental)
1110
- Support for gemini-exp-1206
1211
- Support for copying prompts from the history screen
12+
- Support for editing through diffs / handling truncated full-file edits
1313

1414
Here's an example of Roo-Cline autonomously creating a snake game with "Always approve write operations" and "Always approve browser actions" turned on:
1515

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "Roo Cline",
44
"description": "A fork of Cline, an autonomous coding agent, with some added experimental configuration and automation features.",
55
"publisher": "RooVeterinaryInc",
6-
"version": "2.1.17",
6+
"version": "2.1.18",
77
"icon": "assets/icons/rocket.png",
88
"galleryBanner": {
99
"color": "#617A91",

src/core/diff/strategies/__tests__/search-replace.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,23 @@ function test() {
181181
expect(result).toBe("\tfunction test() {\n\t\t// First comment\n\t\t// Second comment\n\t\treturn true;\n\t}")
182182
})
183183

184+
it('should handle Windows-style CRLF line endings', () => {
185+
const originalContent = "function test() {\r\n return true;\r\n}\r\n"
186+
const diffContent = `test.ts
187+
<<<<<<< SEARCH
188+
function test() {
189+
return true;
190+
}
191+
=======
192+
function test() {
193+
return false;
194+
}
195+
>>>>>>> REPLACE`
196+
197+
const result = strategy.applyDiff(originalContent, diffContent)
198+
expect(result).toBe("function test() {\r\n return false;\r\n}\r\n")
199+
})
200+
184201
it('should return false if search content does not match', () => {
185202
const originalContent = `function hello() {
186203
console.log("hello")

src/core/diff/strategies/search-replace.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,13 @@ Your search/replace content here
7070

7171
const [_, searchContent, replaceContent] = match;
7272

73-
// Split content into lines
74-
const searchLines = searchContent.trim().split('\n');
75-
const replaceLines = replaceContent.trim().split('\n');
76-
const originalLines = originalContent.split('\n');
73+
// Detect line ending from original content
74+
const lineEnding = originalContent.includes('\r\n') ? '\r\n' : '\n';
75+
76+
// Split content into lines, handling both \n and \r\n
77+
const searchLines = searchContent.trim().split(/\r?\n/);
78+
const replaceLines = replaceContent.trim().split(/\r?\n/);
79+
const originalLines = originalContent.split(/\r?\n/);
7780

7881
// Find the search content in the original
7982
let matchIndex = -1;
@@ -166,6 +169,6 @@ Your search/replace content here
166169
const beforeMatch = originalLines.slice(0, matchIndex);
167170
const afterMatch = originalLines.slice(matchIndex + searchLines.length);
168171

169-
return [...beforeMatch, ...indentedReplace, ...afterMatch].join('\n');
172+
return [...beforeMatch, ...indentedReplace, ...afterMatch].join(lineEnding);
170173
}
171-
}
174+
}

webview-ui/src/components/settings/SettingsView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ const SettingsView = ({ onDone }: SettingsViewProps) => {
296296

297297
<div style={{ marginBottom: 5 }}>
298298
<VSCodeCheckbox checked={diffEnabled} onChange={(e: any) => setDiffEnabled(e.target.checked)}>
299-
<span style={{ fontWeight: "500" }}>Enable editing through diffs (very experimental!)</span>
299+
<span style={{ fontWeight: "500" }}>Enable editing through diffs</span>
300300
</VSCodeCheckbox>
301301
<p
302302
style={{

0 commit comments

Comments
 (0)