summaryrefslogtreecommitdiff
path: root/src/window.cc
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2018-06-11 14:44:58 +1000
committerMaxime Coste <mawww@kakoune.org>2018-06-11 15:10:30 +1000
commit0d3a1b59555a25fdf564a4728272183a73e0192c (patch)
tree75785e31a7c9a74da94a5994b8b6c800d1719780 /src/window.cc
parentdf90ba598470fe722ac6322fff43928f07782c59 (diff)
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
Diffstat (limited to 'src/window.cc')
-rw-r--r--src/window.cc10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/window.cc b/src/window.cc
index 19cde54e..09babb8f 100644
--- a/src/window.cc
+++ b/src/window.cc
@@ -126,6 +126,16 @@ const DisplayBuffer& Window::update_display_buffer(const Context& context)
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();
m_display_buffer.set_timestamp(buffer().timestamp());
lines.clear();