Try to keep window position fixed when buffer gets modified

Adapt window position to the changes that happened in the buffer
since last redraw.

Fixes #1989
This commit is contained in:
Maxime Coste 2018-06-11 14:44:58 +10:00
parent df90ba5984
commit 0d3a1b5955
2 changed files with 11 additions and 1 deletions

View File

@ -169,7 +169,7 @@ public:
private: private:
LineList m_lines; LineList m_lines;
BufferRange m_range; BufferRange m_range;
size_t m_timestamp; size_t m_timestamp = -1;
}; };
} }

View File

@ -126,6 +126,16 @@ 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{};
if (m_display_buffer.timestamp() != -1)
{
for (auto&& change : buffer().changes_since(m_display_buffer.timestamp()))
{
if (change.begin.line < m_position.line)
m_position.line += (change.type == Buffer::Change::Insert ? 1 : -1) *
(change.end.line - change.begin.line);
}
}
DisplayBuffer::LineList& lines = m_display_buffer.lines(); DisplayBuffer::LineList& lines = m_display_buffer.lines();
m_display_buffer.set_timestamp(buffer().timestamp()); m_display_buffer.set_timestamp(buffer().timestamp());
lines.clear(); lines.clear();