Skip to content

Commit 3d07d79

Browse files
committed
Fix line splitting and improve line sequence matching for cross-platform compatibility and indentation handling
1 parent 65f9ac3 commit 3d07d79

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

‎packages/vscode/src/commands/apply-chat-response-command/handlers/truncated-handler.ts‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ function process_truncated_content(
129129
new_text: string,
130130
original_text: string
131131
): string {
132-
const new_lines = new_text.split('\n')
133-
const original_lines = original_text.split('\n')
132+
const new_lines = new_text.split(/\r?\n/)
133+
const original_lines = original_text.split(/\r?\n/)
134134

135135
const blocks: { type: 'code' | 'truncation'; lines: string[] }[] = []
136136
let buffer: string[] = []
@@ -250,10 +250,23 @@ function find_line_sequence(
250250
if (sequence.length == 0) return -1
251251
if (start_idx >= lines.length) return -1
252252

253+
// First pass: exact match (checking for correct indentation)
253254
for (let i = start_idx; i <= lines.length - sequence.length; i++) {
254255
let match = true
255256
for (let j = 0; j < sequence.length; j++) {
256-
if (lines[i + j].trim() !== sequence[j].trim()) {
257+
if (lines[i + j] != sequence[j]) {
258+
match = false
259+
break
260+
}
261+
}
262+
if (match) return i
263+
}
264+
265+
// Second pass: loose match (trim)
266+
for (let i = start_idx; i <= lines.length - sequence.length; i++) {
267+
let match = true
268+
for (let j = 0; j < sequence.length; j++) {
269+
if (lines[i + j].trim() != sequence[j].trim()) {
257270
match = false
258271
break
259272
}

0 commit comments

Comments
 (0)