@@ -27,6 +27,8 @@ class DiffWidget(Vertical): |
| 27 | 27 | self.is_new_file = not old_string # True if creating new file |
| 28 | 28 | |
| 29 | 29 | def compose(self) -> ComposeResult: |
| 30 | + from rich.markup import escape |
| 31 | + |
| 30 | 32 | # Calculate stats |
| 31 | 33 | old_lines = self.old_string.splitlines() if self.old_string else [] |
| 32 | 34 | new_lines = self.new_string.splitlines() |
@@ -43,6 +45,14 @@ class DiffWidget(Vertical): |
| 43 | 45 | f"└ [green]+{len(new_lines)}[/green] lines", |
| 44 | 46 | classes="diff-stats", |
| 45 | 47 | ) |
| 48 | + # Show preview of content being written |
| 49 | + preview = self.new_string[:100].replace('\n', ' ') |
| 50 | + if len(self.new_string) > 100: |
| 51 | + preview += "..." |
| 52 | + yield Static( |
| 53 | + f" [dim]{escape(preview)}[/dim]", |
| 54 | + classes="diff-preview", |
| 55 | + ) |
| 46 | 56 | else: |
| 47 | 57 | added = sum(1 for line in new_lines if line not in old_lines) |
| 48 | 58 | removed = sum(1 for line in old_lines if line not in new_lines) |
@@ -61,6 +71,21 @@ class DiffWidget(Vertical): |
| 61 | 71 | f"└ {', '.join(stats_parts)} lines", |
| 62 | 72 | classes="diff-stats", |
| 63 | 73 | ) |
| 74 | + # Show what's being replaced |
| 75 | + old_preview = self.old_string[:50].replace('\n', ' ') |
| 76 | + new_preview = self.new_string[:50].replace('\n', ' ') |
| 77 | + if len(self.old_string) > 50: |
| 78 | + old_preview += "..." |
| 79 | + if len(self.new_string) > 50: |
| 80 | + new_preview += "..." |
| 81 | + yield Static( |
| 82 | + f" [red]-[/red] [dim]{escape(old_preview)}[/dim]", |
| 83 | + classes="diff-preview-old", |
| 84 | + ) |
| 85 | + yield Static( |
| 86 | + f" [green]+[/green] [dim]{escape(new_preview)}[/dim]", |
| 87 | + classes="diff-preview-new", |
| 88 | + ) |
| 64 | 89 | |
| 65 | 90 | # Diff content |
| 66 | 91 | yield Static( |