Review fixes: exception-safe AdoptOriginal; Qt draws cells straddling the left edge
AdoptOriginal cleared the table before allocating its piece list, so a bad_alloc left a live buffer with the file's size and no pieces; OpenFromFile no longer caught it either. The piece list is now built before anything is touched (the rest cannot throw) and OpenFromFile again reports "File too large to load" with the buffer unchanged. Qt skipped every character starting left of the horizontal scroll offset, so a tab or wide character straddling it left blank columns while selection and cursor still used the real ones. Such a character is now drawn at its own column and clipped by the viewport. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015rcVQiiWyTzoNrsvLSaAfB
This commit is contained in:
+13
-2
@@ -204,10 +204,21 @@ protected:
|
||||
p.drawText(QPointF(col_x(col), baseline), QString::fromUtf8(d, static_cast<int>(n)));
|
||||
};
|
||||
auto draw_seg = [&](std::size_t s, std::size_t e, const QColor &color) {
|
||||
// Only the visible columns: characters left of coloffs or
|
||||
// right of the viewport are skipped.
|
||||
// Only the visible columns: characters that end at or
|
||||
// before coloffs, or start right of the viewport, are
|
||||
// skipped. A tab or wide character straddling coloffs
|
||||
// starts left of it; it is drawn at its own column and
|
||||
// the clip cuts its left part.
|
||||
const std::size_t first = s;
|
||||
s = static_cast<std::size_t>(std::lower_bound(col_of.begin() + s, col_of.begin() + e,
|
||||
coloffs) - col_of.begin());
|
||||
if (s > first && col_of[s] > coloffs) {
|
||||
// The character before s ends past coloffs: back up to
|
||||
// its first byte.
|
||||
--s;
|
||||
while (s > first && (static_cast<unsigned char>(line[s]) & 0xC0) == 0x80)
|
||||
--s;
|
||||
}
|
||||
e = static_cast<std::size_t>(std::lower_bound(col_of.begin() + s, col_of.begin() + e,
|
||||
coloffs + vis_cols) - col_of.begin());
|
||||
if (e <= s)
|
||||
|
||||
Reference in New Issue
Block a user