From b72acfe1f84501564d2048570c5dc32b45daedbd Mon Sep 17 00:00:00 2001 From: Claire Foster Date: Thu, 9 Nov 2023 13:49:21 +1000 Subject: [PATCH 1/2] Fix highlighting of ranges which start with non-ascii chars --- src/source_files.jl | 9 +++++++-- test/source_files.jl | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/source_files.jl b/src/source_files.jl index 06cae008..cf81c7b1 100644 --- a/src/source_files.jl +++ b/src/source_files.jl @@ -124,6 +124,10 @@ function Base.thisind(source::SourceFile, i::Int) thisind(source.code, i - source.byte_offset) + source.byte_offset end +function Base.nextind(source::SourceFile, i::Int) + nextind(source.code, i - source.byte_offset) + source.byte_offset +end + Base.firstindex(source::SourceFile) = firstindex(source.code) + source.byte_offset Base.lastindex(source::SourceFile) = lastindex(source.code) + source.byte_offset @@ -218,7 +222,8 @@ function highlight(io::IO, source::SourceFile, range::UnitRange; hitext = source[p:q] print(io, source[x:p-1]) _printstyled(io, hitext; bgcolor=color) - print(io, source[q+1:d]) + #print(io, source[q+1:d]) + print(io, source[nextind(source,q):d]) if d >= firstindex(source) && source[thisind(source, d)] != '\n' print(io, "\n") end @@ -249,7 +254,7 @@ function highlight(io::IO, source::SourceFile, range::UnitRange; print(io, "⋮\n") _printstyled(io, source[z:q]; bgcolor=color) end - print(io, source[q+1:d]) + print(io, source[nextind(source, q):d]) source[thisind(source, d)] == '\n' || print(io, "\n") qline = source[c:q] _print_marker_line(io, "", qline, true, false, marker_line_color, note, notecolor) diff --git a/test/source_files.jl b/test/source_files.jl index 9a1548f1..0e36b7fe 100644 --- a/test/source_files.jl +++ b/test/source_files.jl @@ -103,6 +103,9 @@ end @test sprint(highlight, src, 3:4) == "abcd\n# └┘\nαβγδ\n+-*/" @test sprint(highlight, src, 4:4) == "abcd\n# ╙\nαβγδ\n+-*/" @test sprint(highlight, src, 5:5) == "abcd\n# └\nαβγδ\n+-*/" + @test sprint(highlight, src, 6:6) == "abcd\nαβγδ\n╙\n+-*/" + @test sprint(highlight, src, 6:9) == "abcd\nαβγδ\n└┘\n+-*/" + @test sprint(highlight, src, 8:8) == "abcd\nαβγδ\n#╙\n+-*/" # multi-byte chars @test sprint(highlight, src, 8:13) == """ @@ -149,6 +152,18 @@ end αβγδ #┘ +-*/""" + @test sprint(highlight, src, 6:15) == """ + abcd + ┌─── + αβγδ + +-*/ + ┘""" + @test sprint(highlight, src, 8:15) == """ + abcd + #┌── + αβγδ + +-*/ + ┘""" @test sprint(highlight, src, 1:18) == """ ┌─── abcd From c1aba1574215e46de734e3b15468accc4ed45bf0 Mon Sep 17 00:00:00 2001 From: Claire Foster Date: Thu, 9 Nov 2023 16:49:51 +1000 Subject: [PATCH 2/2] fixup! Fix highlighting of ranges which start with non-ascii chars --- src/source_files.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/source_files.jl b/src/source_files.jl index cf81c7b1..a8051a59 100644 --- a/src/source_files.jl +++ b/src/source_files.jl @@ -124,7 +124,7 @@ function Base.thisind(source::SourceFile, i::Int) thisind(source.code, i - source.byte_offset) + source.byte_offset end -function Base.nextind(source::SourceFile, i::Int) +function Base.nextind(source::SourceFile, i::Integer) nextind(source.code, i - source.byte_offset) + source.byte_offset end