Skip to content

Commit

Permalink
Reimplement TextBuffer::Reflow
Browse files Browse the repository at this point in the history
  • Loading branch information
lhecker committed Aug 15, 2023
1 parent b556594 commit 3d463f1
Show file tree
Hide file tree
Showing 12 changed files with 321 additions and 439 deletions.
38 changes: 32 additions & 6 deletions src/buffer/out/Row.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,16 @@ void ROW::TransferAttributes(const til::small_rle<TextAttribute, uint16_t, 1>& a

void ROW::CopyFrom(const ROW& source)
{
RowCopyTextFromState state{ .source = source };
CopyTextFrom(state);
TransferAttributes(source.Attributes(), _columnCount);
_lineRendition = source._lineRendition;
_wrapForced = source._wrapForced;

RowCopyTextFromState state{
.source = source,
.columnLimit = LineRenditionColumns(),
};
CopyTextFrom(state);

TransferAttributes(source.Attributes(), _columnCount);
}

// Returns the previous possible cursor position, preceding the given column.
Expand All @@ -284,7 +289,17 @@ til::CoordType ROW::NavigateToPrevious(til::CoordType column) const noexcept
// Returns the row width if column is beyond the width of the row.
til::CoordType ROW::NavigateToNext(til::CoordType column) const noexcept
{
return _adjustForward(_clampedColumn(column + 1));
return _adjustForward(_clampedColumnInclusive(column + 1));
}

til::CoordType ROW::AdjustBackward(til::CoordType column) const noexcept
{
return _adjustBackward(_clampedColumn(column));
}

til::CoordType ROW::AdjustForward(til::CoordType column) const noexcept
{
return _adjustForward(_clampedColumnInclusive(column));
}

uint16_t ROW::_adjustBackward(uint16_t column) const noexcept
Expand Down Expand Up @@ -641,11 +656,12 @@ try
if (sourceColBeg < sourceColLimit)
{
charOffsets = source._charOffsets.subspan(sourceColBeg, static_cast<size_t>(sourceColLimit) - sourceColBeg + 1);
const auto charsOffset = charOffsets.front() & CharOffsetsMask;
const auto beg = size_t{ charOffsets.front() } & CharOffsetsMask;
const auto end = size_t{ charOffsets.back() } & CharOffsetsMask;
// We _are_ using span. But C++ decided that string_view and span aren't convertible.
// _chars is a std::span for performance and because it refers to raw, shared memory.
#pragma warning(suppress : 26481) // Don't use pointer arithmetic. Use span instead (bounds.1).
chars = { source._chars.data() + charsOffset, source._chars.size() - charsOffset };
chars = { source._chars.data() + beg, end - beg };
}

WriteHelper h{ *this, state.columnBegin, state.columnLimit, chars };
Expand Down Expand Up @@ -867,6 +883,16 @@ til::CoordType ROW::MeasureLeft() const noexcept

til::CoordType ROW::MeasureRight() const noexcept
{
if (_wrapForced)
{
auto width = _columnCount;
if (_doubleBytePadded)
{
width--;
}
return width;
}

const auto text = GetText();
const auto beg = text.begin();
const auto end = text.end();
Expand Down
2 changes: 2 additions & 0 deletions src/buffer/out/Row.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ class ROW final

til::CoordType NavigateToPrevious(til::CoordType column) const noexcept;
til::CoordType NavigateToNext(til::CoordType column) const noexcept;
til::CoordType AdjustBackward(til::CoordType column) const noexcept;
til::CoordType AdjustForward(til::CoordType column) const noexcept;

void ClearCell(til::CoordType column);
OutputCellIterator WriteCells(OutputCellIterator it, til::CoordType columnBegin, std::optional<bool> wrap = std::nullopt, std::optional<til::CoordType> limitRight = std::nullopt);
Expand Down
Loading

0 comments on commit 3d463f1

Please sign in to comment.