Skip to content

Commit

Permalink
Merge pull request #1569 from contour-terminal/fix/space_resize
Browse files Browse the repository at this point in the history
Preserve spaces on resize
  • Loading branch information
christianparpart authored Jul 21, 2024
2 parents 6a98a73 + 1957946 commit 92c47fd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
1 change: 1 addition & 0 deletions metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
<li>Do not export the `TERM` environment variable on Windows OS (when using ConPTY).</li>
<li>Fixes resize of trivial line (#916)</li>
<li>Fixes copying of wrapped line</li>
<li>Fixes deletion of spaces on resize </li>
<li>Fixes forwarding of input while in normal mode (#1468)</li>
<li>Fixes OSC-8 link id collision (#1499)</li>
<li>Fixed overlap of glyphs for long codepoints (#1349)</li>
Expand Down
2 changes: 1 addition & 1 deletion src/vtbackend/CellUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ template <CellConcept Cell>
template <CellConcept Cell>
[[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 <CellConcept Cell>
Expand Down
19 changes: 17 additions & 2 deletions src/vtbackend/Grid_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -914,11 +914,26 @@ TEST_CASE("Grid resize with wrap and spaces", "[grid]")
auto lineTrivial = Line<Cell>(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");
}

Expand Down
13 changes: 5 additions & 8 deletions src/vtbackend/Line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,11 @@ typename Line<Cell>::InflatedBuffer Line<Cell>::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;
Expand Down

0 comments on commit 92c47fd

Please sign in to comment.