From 621e027b2ac38a9cfc775a2afdff5235167b8b22 Mon Sep 17 00:00:00 2001 From: Luc Briand <34173752+Keluaa@users.noreply.github.com> Date: Sun, 21 Apr 2024 18:12:05 +0200 Subject: [PATCH] Fix tab alignment --- src/display.jl | 4 ++-- test/runtests.jl | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/display.jl b/src/display.jl index 43acf4a..96c73f5 100644 --- a/src/display.jl +++ b/src/display.jl @@ -5,9 +5,9 @@ function print_str_with_tabs(io::IO, str, tab_replacement) str_pos = 1 column_pos = 1 while (tab_pos = findnext('\t', str, str_pos); !isnothing(tab_pos)) - str_part_len = (tab_pos - 1) - str_pos + str_part_len = (tab_pos - 1) - str_pos + 1 column_pos += str_part_len - tab_len = full_tab_len - mod(column_pos, full_tab_len) + tab_len = full_tab_len - mod(column_pos - 1, full_tab_len) print(io, @view(str[str_pos:tab_pos - 1]), @view(tab_replacement[1:tab_len])) column_pos += tab_len str_pos = tab_pos + 1 diff --git a/test/runtests.jl b/test/runtests.jl index 69058c9..d4752d3 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -407,6 +407,12 @@ end @test str == expected_str end end + + # Lines with changes use another code path for tabs alignment + diff = CodeDiffs.compare_show("\tabc\t123\n\tabc\t456", "\tabc\t126\n\tabc\t456") + diff_str = split(display_str(diff; color=false), '\n') + @test startswith(diff_str[1], " abc 1") + @test startswith(diff_str[2], " abc 4") end @testset "@code_diff" begin