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:
Claude
2026-09-24 12:19:59 -07:00
committed by Kyle Isom
parent e1ebf5900b
commit 3be85ef4ad
4 changed files with 30 additions and 9 deletions
+6 -2
View File
@@ -206,13 +206,17 @@ PieceTable::Clear()
void
PieceTable::AdoptOriginal(std::string &&bytes)
{
// Allocate before touching the current content: if this throws, the
// table is unchanged (everything below is non-throwing).
std::vector<Piece> pieces;
if (!bytes.empty())
pieces.push_back(Piece{Source::Original, 0, bytes.size()});
Clear();
std::string().swap(add_); // release a previous content's capacity
std::string().swap(materialized_);
original_ = std::move(bytes);
total_size_ = original_.size();
if (total_size_ > 0)
pieces_.push_back(Piece{Source::Original, 0, total_size_});
pieces_.swap(pieces);
version_++;
}