From 7ee4a3b40df5960063d9cd0606069a446d254a45 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Mon, 8 Feb 2021 04:37:50 +0100 Subject: [PATCH] Indent empty lines inside block --- src/fish_tests.cpp | 2 +- src/parse_util.cpp | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index 9772075ca..55191f4b0 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -1389,7 +1389,7 @@ static void test_indents() { add_test(&tests, // 0, "if", 1, " foo", // 1, "\nif", 2, " bar", // - 1, "\n", // FIXME: this should be 2 but parse_util_compute_indents has a bug + 2, "\n", // 1, "\nend\n"); add_test(&tests, // diff --git a/src/parse_util.cpp b/src/parse_util.cpp index e3d085a8b..9fc9fdbe2 100644 --- a/src/parse_util.cpp +++ b/src/parse_util.cpp @@ -727,18 +727,14 @@ std::vector parse_util_compute_indents(const wcstring &src) { // the newline "belongs" to the if statement as it ends its job. // But when rendered, it visually belongs to the job list. - // FIXME: if there's a middle newline, we will indent it wrongly. - // For example: - // if true - // - // end - // Here the middle newline should be indented by 1. - size_t idx = src_size; int next_indent = iv.last_indent; while (idx--) { if (src.at(idx) == L'\n') { - indents.at(idx) = next_indent; + bool empty_middle_line = idx + 1 < src_size && src.at(idx + 1) == L'\n'; + if (!empty_middle_line) { + indents.at(idx) = next_indent; + } } else { next_indent = indents.at(idx); }