|
| 1 | +// packages/vscode/src/commands/apply-chat-response-command/utils/clipboard-parser/clipboard-parser.ts |
1 | 2 | import { cleanup_api_response } from '@/utils/cleanup-api-response' |
2 | 3 | import { extract_path_from_line_of_code } from '@shared/utils/extract-path-from-line-of-code' |
3 | 4 | import { Diff, extract_diffs } from './extract-diff-patches' |
@@ -339,6 +340,12 @@ export const parse_multiple_files = (params: { |
339 | 340 |
|
340 | 341 | // Handle nested backticks |
341 | 342 | if (trimmed_line.startsWith('```') && trimmed_line !== '```') { |
| 343 | + if ( |
| 344 | + backtick_nesting_level === 1 && |
| 345 | + (current_language === 'markdown' || current_language === 'md') |
| 346 | + ) { |
| 347 | + is_first_content_line = true |
| 348 | + } |
342 | 349 | backtick_nesting_level++ |
343 | 350 | } else if ( |
344 | 351 | trimmed_line == '```' && |
@@ -505,25 +512,24 @@ export const parse_multiple_files = (params: { |
505 | 512 | } |
506 | 513 |
|
507 | 514 | if (extracted_filename) { |
508 | | - if ( |
509 | | - (current_language === 'markdown' || current_language === 'md') && |
510 | | - current_file_name |
511 | | - ) { |
512 | | - // This is a new file inside a markdown block. Save the previous one. |
513 | | - const cleaned_content = current_content.trim() |
514 | | - if (has_real_code(cleaned_content)) { |
515 | | - const file_key = `${ |
516 | | - current_workspace_name || '' |
517 | | - }:${current_file_name}` |
518 | | - if (files_map.has(file_key)) { |
519 | | - const existing_file = files_map.get(file_key)! |
520 | | - existing_file.content += '\n\n' + cleaned_content |
521 | | - } else { |
522 | | - files_map.set(file_key, { |
523 | | - file_path: current_file_name, |
524 | | - content: cleaned_content, |
525 | | - workspace_name: current_workspace_name |
526 | | - }) |
| 515 | + if (current_language === 'markdown' || current_language === 'md') { |
| 516 | + if (current_file_name) { |
| 517 | + // This is a new file inside a markdown block. Save the previous one. |
| 518 | + const cleaned_content = current_content.trim() |
| 519 | + if (has_real_code(cleaned_content)) { |
| 520 | + const file_key = `${ |
| 521 | + current_workspace_name || '' |
| 522 | + }:${current_file_name}` |
| 523 | + if (files_map.has(file_key)) { |
| 524 | + const existing_file = files_map.get(file_key)! |
| 525 | + existing_file.content += '\n\n' + cleaned_content |
| 526 | + } else { |
| 527 | + files_map.set(file_key, { |
| 528 | + file_path: current_file_name, |
| 529 | + content: cleaned_content, |
| 530 | + workspace_name: current_workspace_name |
| 531 | + }) |
| 532 | + } |
527 | 533 | } |
528 | 534 | } |
529 | 535 | current_content = '' |
@@ -579,10 +585,16 @@ export const parse_multiple_files = (params: { |
579 | 585 | line.trim().startsWith('```') |
580 | 586 | ) |
581 | 587 | ) { |
582 | | - if (current_content) { |
583 | | - current_content += '\n' + line |
584 | | - } else { |
585 | | - current_content = line |
| 588 | + if ( |
| 589 | + !lang_is_markdown || |
| 590 | + is_markdown_file || |
| 591 | + backtick_nesting_level > 1 |
| 592 | + ) { |
| 593 | + if (current_content) { |
| 594 | + current_content += '\n' + line |
| 595 | + } else { |
| 596 | + current_content = line |
| 597 | + } |
586 | 598 | } |
587 | 599 | } |
588 | 600 |
|
|
0 commit comments