From 19579463fa303057c7a6004e9299bcf9a505c29b Mon Sep 17 00:00:00 2001 From: Yaraslau Tamashevich Date: Tue, 16 Jul 2024 09:14:29 +0300 Subject: [PATCH] Preserve spaces on resize Signed-off-by: Christian Parpart --- metainfo.xml | 1 + src/vtbackend/CellUtil.h | 2 +- src/vtbackend/Grid_test.cpp | 19 +++++++++++++++++-- src/vtbackend/Line.cpp | 13 +++++-------- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/metainfo.xml b/metainfo.xml index 0bee96c0ef..ff5025e8c3 100644 --- a/metainfo.xml +++ b/metainfo.xml @@ -134,6 +134,7 @@
  • Do not export the `TERM` environment variable on Windows OS (when using ConPTY).
  • Fixes resize of trivial line (#916)
  • Fixes copying of wrapped line
  • +
  • Fixes deletion of spaces on resize
  • Fixes forwarding of input while in normal mode (#1468)
  • Fixes OSC-8 link id collision (#1499)
  • Fixed overlap of glyphs for long codepoints (#1349)
  • diff --git a/src/vtbackend/CellUtil.h b/src/vtbackend/CellUtil.h index df516b22f4..8c1285338d 100644 --- a/src/vtbackend/CellUtil.h +++ b/src/vtbackend/CellUtil.h @@ -93,7 +93,7 @@ template template [[nodiscard]] inline bool empty(Cell const& cell) noexcept { - return (cell.codepointCount() == 0 || cell.codepoint(0) == 0x20) && !cell.imageFragment(); + return (cell.codepointCount() == 0) && !cell.imageFragment(); } template diff --git a/src/vtbackend/Grid_test.cpp b/src/vtbackend/Grid_test.cpp index 76bdad934a..2a9d0386d9 100644 --- a/src/vtbackend/Grid_test.cpp +++ b/src/vtbackend/Grid_test.cpp @@ -914,11 +914,26 @@ TEST_CASE("Grid resize with wrap and spaces", "[grid]") auto lineTrivial = Line(LineFlag::None, trivial); grid.lineAt(LineOffset(0)) = lineTrivial; - {}(void) grid.resize(PageSize { LineCount(3), ColumnCount(6) }, CellLocation {}, false); + (void) grid.resize(PageSize { LineCount(3), ColumnCount(6) }, CellLocation {}, false); REQUIRE(grid.lineText(LineOffset(-1)) == "a a a "); REQUIRE(grid.lineText(LineOffset(0)) == "a "); REQUIRE(grid.lineText(LineOffset(1)) == " "); - {}(void) grid.resize(PageSize { LineCount(3), ColumnCount(7) }, CellLocation {}, false); + (void) grid.resize(PageSize { LineCount(3), ColumnCount(7) }, CellLocation {}, false); + REQUIRE(grid.lineText(LineOffset(0)) == "a a a a"); + (void) grid.resize(PageSize { LineCount(3), ColumnCount(5) }, CellLocation {}, false); + REQUIRE(grid.lineText(LineOffset(-1)) == "a a a"); + REQUIRE(grid.lineText(LineOffset(0)) == " a "); + REQUIRE(grid.lineText(LineOffset(1)) == " "); + (void) grid.resize(PageSize { LineCount(3), ColumnCount(4) }, CellLocation {}, false); + REQUIRE(grid.lineText(LineOffset(-1)) == "a a "); + REQUIRE(grid.lineText(LineOffset(0)) == "a a "); + REQUIRE(grid.lineText(LineOffset(1)) == " "); + (void) grid.resize(PageSize { LineCount(3), ColumnCount(3) }, CellLocation {}, false); + REQUIRE(grid.lineText(LineOffset(-2)) == "a a"); + REQUIRE(grid.lineText(LineOffset(-1)) == " a "); + REQUIRE(grid.lineText(LineOffset(0)) == "a "); + REQUIRE(grid.lineText(LineOffset(1)) == " "); + (void) grid.resize(PageSize { LineCount(3), ColumnCount(7) }, CellLocation {}, false); REQUIRE(grid.lineText(LineOffset(0)) == "a a a a"); } diff --git a/src/vtbackend/Line.cpp b/src/vtbackend/Line.cpp index a8cc99dd3a..cda94adfab 100644 --- a/src/vtbackend/Line.cpp +++ b/src/vtbackend/Line.cpp @@ -56,14 +56,11 @@ typename Line::InflatedBuffer Line::reflow(ColumnCount newColumnCoun buffer.erase(reflowStart, buffer.end()); assert(size() == newColumnCount); #if 0 - if (removedColumns.size() > 0 && - std::any_of(removedColumns.begin(), removedColumns.end(), - [](Cell const& x) - { - if (!x.empty()) - fmt::print("non-empty cell in reflow: {}\n", x.toUtf8()); - return !x.empty(); - })) + if (removedColumns.size() > 0 && std::ranges::any_of(removedColumns, [](Cell const& x) { + if (!x.empty()) + fmt::print("non-empty cell in reflow: {}\n", x.toUtf8()); + return !x.empty(); + })) printf("Wrapping around\n"); #endif return removedColumns;