diff --git a/src/runestone.jl b/src/runestone.jl index 2d4b6d6..16bb83e 100644 --- a/src/runestone.jl +++ b/src/runestone.jl @@ -2485,13 +2485,16 @@ function indent_listlike( end # Kid just before the closing token should be a newline and it should be tagged with # pre-dedent. - if close_idx - 1 == open_idx + 1 + if idx_after_leading_nl == close_idx # Just a single kid which should then have both leading and trailing newline if any_kid_changed - # Modify this kid again by popping from the list and backtrack the stream + # Modify this kid again by popping from the list kid = pop!(kids′) - seek(ctx.fmt_io, position(ctx.fmt_io) - span(kid)) + else + kid = kids[close_idx - 1] end + # Backtrack the stream + seek(ctx.fmt_io, position(ctx.fmt_io) - span(kid)) else kid = kids[close_idx - 1] end diff --git a/test/runtests.jl b/test/runtests.jl index 66d7d8e..a6559d8 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -397,6 +397,9 @@ end # Non space whitespace (TODO: Not sure if a JuliaSyntax bug or not?) @test format_string(String(UInt8[0x61, 0x20, 0x3d, 0x3d, 0x20, 0xc2, 0xa0, 0x62, 0x3a, 0x63])) == "a == b:c" + # Edge case with comment and no items + @test format_string("[# a\n]") == "[# a\n]" + @test format_string("[ # a\n]") == "[ # a\n]" end @testset "whitespace around ->" begin