Store the timestamp at which a display buffer was generated

Coordinates inside a display buffer are only valid for a certain
buffer content, they cannot be used once the buffer has been
modified.

Fixes #2034
This commit is contained in:
Maxime Coste 2018-05-08 21:55:15 +10:00
parent 148d6c205b
commit e8c648b7b7
2 changed files with 11 additions and 2 deletions

View File

@ -163,9 +163,13 @@ public:
// Optimize all lines, set DisplayLine::optimize // Optimize all lines, set DisplayLine::optimize
void optimize(); void optimize();
void set_timestamp(size_t timestamp) { m_timestamp = timestamp; }
size_t timestamp() const { return m_timestamp; }
private: private:
LineList m_lines; LineList m_lines;
BufferRange m_range; BufferRange m_range;
size_t m_timestamp;
}; };
} }

View File

@ -126,6 +126,7 @@ const DisplayBuffer& Window::update_display_buffer(const Context& context)
auto start_time = profile ? Clock::now() : Clock::time_point{}; auto start_time = profile ? Clock::now() : Clock::time_point{};
DisplayBuffer::LineList& lines = m_display_buffer.lines(); DisplayBuffer::LineList& lines = m_display_buffer.lines();
m_display_buffer.set_timestamp(buffer().timestamp());
lines.clear(); lines.clear();
if (m_dimensions == DisplayCoord{0,0}) if (m_dimensions == DisplayCoord{0,0})
@ -283,6 +284,9 @@ BufferCoord find_buffer_coord(const DisplayLine& line, const Buffer& buffer,
Optional<DisplayCoord> Window::display_position(BufferCoord coord) const Optional<DisplayCoord> Window::display_position(BufferCoord coord) const
{ {
if (m_display_buffer.timestamp() != buffer().timestamp())
return {};
LineCount l = 0; LineCount l = 0;
for (auto& line : m_display_buffer.lines()) for (auto& line : m_display_buffer.lines())
{ {
@ -296,7 +300,8 @@ Optional<DisplayCoord> Window::display_position(BufferCoord coord) const
BufferCoord Window::buffer_coord(DisplayCoord coord) const BufferCoord Window::buffer_coord(DisplayCoord coord) const
{ {
if (m_display_buffer.lines().empty()) if (m_display_buffer.timestamp() != buffer().timestamp() or
m_display_buffer.lines().empty())
return {0, 0}; return {0, 0};
if (coord <= 0_line) if (coord <= 0_line)
coord = {0,0}; coord = {0,0};