File tree Expand file tree Collapse file tree
packages/vscode/src/commands/apply-chat-response-command/handlers Expand file tree Collapse file tree Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments