Skip to content

Commit

Permalink
Merge pull request #10 from Keluaa/fix_tabs
Browse files Browse the repository at this point in the history
Fix tab alignment
  • Loading branch information
Keluaa authored Apr 21, 2024
2 parents cb2125a + 621e027 commit ad91714
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ad91714

Please sign in to comment.