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:
@@ -617,11 +617,16 @@ Buffer::OpenFromFile(const std::string &path, std::string &err)
|
||||
return false;
|
||||
}
|
||||
(void) kte::syscall::Close(fd);
|
||||
// Build the new content aside and swap it in only once complete: if the
|
||||
// copy runs out of memory, the buffer keeps its old text (clearing first
|
||||
// left an empty buffer that a later save wrote over the file).
|
||||
// The bytes become the piece table's original storage, uncopied.
|
||||
content_.AdoptOriginal(std::move(data)); // not used under PieceTable
|
||||
// The bytes become the piece table's original storage, uncopied. If that
|
||||
// runs out of memory the buffer keeps its old text (clearing first left
|
||||
// an empty buffer that a later save wrote over the file).
|
||||
try {
|
||||
content_.AdoptOriginal(std::move(data));
|
||||
} catch (const std::bad_alloc &) {
|
||||
err = "File too large to load: " + norm;
|
||||
kte::ErrorHandler::Instance().Error("Buffer", err, norm);
|
||||
return false;
|
||||
}
|
||||
filename_ = norm;
|
||||
is_file_backed_ = true;
|
||||
is_virtual_ = false;
|
||||
|
||||
Reference in New Issue
Block a user