diff --git a/src/gui/BufferPane.cc b/src/gui/BufferPane.cc index 648977b..ad5eca2 100644 --- a/src/gui/BufferPane.cc +++ b/src/gui/BufferPane.cc @@ -145,6 +145,31 @@ int BufferPane::update_cursor_row(std::list> & return cursor_row_offset; } +int BufferPane::determine_new_cursor_screen_row() +{ + if (m_screen_lines.size() > 0) + { + if (m_iterator->line() < m_screen_lines.begin()->second.line()) + { + return 0; + } + if (m_iterator->line() > m_screen_lines.rbegin()->second.line()) + { + return m_rows; + } + for (auto screen_line : m_screen_lines) + { + if (screen_line.second.line() == m_iterator->line()) + { + int row_offset; + rows_in_line_with_iterator_offset(screen_line.second, *m_iterator, &row_offset); + return screen_line.first + row_offset; + } + } + } + return 0; +} + void BufferPane::draw() { m_screen_lines.clear(); @@ -334,6 +359,7 @@ void BufferPane::cursor_move(CursorMovement which) } if (moved) { + m_cursor_screen_row = determine_new_cursor_screen_row(); m_window->request_redraw(); } } diff --git a/src/gui/BufferPane.h b/src/gui/BufferPane.h index 348b211..1c1b6c9 100644 --- a/src/gui/BufferPane.h +++ b/src/gui/BufferPane.h @@ -43,6 +43,7 @@ protected: int screen_rows_above_line(const Buffer::Iterator & line, std::list> & backward_lines); int update_cursor_row(std::list> & backward_lines); void walk_line(const Buffer::Iterator & start_of_line, std::function callback); + int determine_new_cursor_screen_row(); int col_x(int col) { return col * m_window->font()->get_advance();