diff --git a/src/runestone.jl b/src/runestone.jl index 5f2bce2..1cd666f 100644 --- a/src/runestone.jl +++ b/src/runestone.jl @@ -1976,7 +1976,8 @@ function indent_loop(ctx::Context, node::Node) kids[for_idx] = add_tag(kids[for_idx], TAG_INDENT) any_kid_changed = true end - block_idx = findnext(x -> kind(x) === K"block", kids, for_idx + 1)::Int + # findlast because the condition can also be a block + block_idx = findlast(x -> kind(x) === K"block", kids)::Int block_node′ = indent_block(ctx, kids[block_idx]) if block_node′ !== nothing kids[block_idx] = block_node′ diff --git a/test/runtests.jl b/test/runtests.jl index 2761508..6593365 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -538,6 +538,8 @@ end @test format_string("for i in I, j in J\n$(sp)x\n$(sp)end") == "for i in I, j in J\n x\nend" # while-end @test format_string("while x\n$(sp)y\n$(sp)end") == "while x\n y\nend" + @test format_string("while (x = 1; x == 1)\n$(sp)y\n$(sp)end") == + "while (x = 1; x == 1)\n y\nend" # try-catch-end @test format_string("try\n$(sp)x\n$(sp)catch\n$(sp)y\n$(sp)end") == "try\n x\ncatch\n y\nend"