From 6ae4e2e4454bc04f5775efb3f517570ff5b277e7 Mon Sep 17 00:00:00 2001 From: Mason Daugherty <61371264+mdrxy@users.noreply.github.com> Date: Tue, 14 Jul 2026 04:05:35 +0000 Subject: [PATCH] fix(code): align context diff rows with changed rows Context diff rows put two spaces after the line number while added and removed rows use one, so unchanged content rendered one column to the right of changed content. Use a single separator space on every row type so the diff body lines up vertically. Co-authored-by: open-swe[bot] --- libs/code/deepagents_code/tui/widgets/diff.py | 2 +- libs/code/tests/unit_tests/tui/widgets/test_diff.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/libs/code/deepagents_code/tui/widgets/diff.py b/libs/code/deepagents_code/tui/widgets/diff.py index 53b87b5563b..d8c09144a67 100644 --- a/libs/code/deepagents_code/tui/widgets/diff.py +++ b/libs/code/deepagents_code/tui/widgets/diff.py @@ -137,7 +137,7 @@ def _compose_diff_content( yield Static( Content.assemble( (f"{glyphs.box_vertical}{old_num:>{width}}", "dim"), - f" {content}", + f" {content}", ), ) old_num += 1 diff --git a/libs/code/tests/unit_tests/tui/widgets/test_diff.py b/libs/code/tests/unit_tests/tui/widgets/test_diff.py index cc2cbcc979f..043a416944f 100644 --- a/libs/code/tests/unit_tests/tui/widgets/test_diff.py +++ b/libs/code/tests/unit_tests/tui/widgets/test_diff.py @@ -120,6 +120,16 @@ def test_added_and_removed_rows_get_css_classes(self) -> None: assert "diff-line-removed" in removed assert context == set() + def test_content_columns_align_across_line_types(self) -> None: + """Context/added/removed rows start their content at the same column.""" + texts = _texts(_rendered(_SAMPLE_DIFF)) + ctx = next(t for t in texts if "ctx" in t) + removed = next(t for t in texts if "removed" in t) + added1 = next(t for t in texts if "added1" in t) + # The gutter glyph, right-aligned line number, and separator must be + # the same width on every row so the diff body lines up vertically. + assert ctx.index("ctx") == removed.index("removed") == added1.index("added1") + def test_max_lines_truncates_with_marker(self) -> None: """Beyond `max_lines`, a truncation marker replaces remaining rows.""" diff = "\n".join(["@@ -1,5 +1,5 @@", *(f"+line{i}" for i in range(5))])