Skip to content

Commit

Permalink
Bugfix: renderer highlights lines when at x-boundary
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-zamora committed Oct 18, 2024
1 parent 659cd02 commit e7ca807
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
36 changes: 36 additions & 0 deletions src/inc/til/point.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,42 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned"
func(y, x1, x2);
}
}

// Similar to iterate_rows above, but the "end" point is exclusive
// and RightExclusive (aka "width") is an allowable coordinate
constexpr void iterate_rows_exclusive(til::CoordType width, auto&& func) const
{
// Copy the members so that the compiler knows it doesn't
// need to re-read them on every loop iteration.
const auto w = width;
auto ax = std::clamp(start.x, 0, w);
auto ay = start.y;
auto bx = std::clamp(end.x, 0, w);
auto by = end.y;

// if start is at RightExclusive,
// treat it as (0, y+1) (left-most point on next line)
if (ax == w)
{
ay++;
ax = 0;
}

// if end is on left boundary,
// treat it as (w, y-1) (RightExclusive on previous line)
if (bx == 0)
{
by--;
bx = w;
}

for (auto y = ay; y <= by; ++y)
{
const auto x1 = y != ay ? 0 : ax;
const auto x2 = y != by ? w : bx;
func(y, x1, x2);
}
}
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/base/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ try
const til::rect vp{ _viewport.ToExclusive() };
for (auto&& sp : spans)
{
sp.iterate_rows(bufferWidth, [&](til::CoordType row, til::CoordType min, til::CoordType max) {
sp.iterate_rows_exclusive(bufferWidth, [&](til::CoordType row, til::CoordType min, til::CoordType max) {
const auto shift = buffer.GetLineRendition(row) != LineRendition::SingleWidth ? 1 : 0;
min <<= shift;
max <<= shift;
Expand Down

0 comments on commit e7ca807

Please sign in to comment.