BufferView updates cursor screen row to follow moved cursor

This commit is contained in:
josh committed 2017-09-03 18:15:37 -04:00
1 parent 14e285041e
commit 359f5bed9f
3 files changed
+87 -4

No files matched your search

+34 -4
View File
@@ -34,12 +34,14 @@ BufferView::Iterator BufferView::vert_iter()
return Iterator(*this);
}
/**************************************************************************
* Internal functions
*************************************************************************/
void BufferView::update()
{
/* Update the cursor screen row in case the cursor position changed. */
m_cursor_screen_row = determine_new_cursor_screen_row();
/* Limit the cursor screen row taking into account view dimensions,
* available buffer contents above and below the current line, and scroll
* offset. */
std::list<std::pair<int, std::shared_ptr<Buffer::Iterator>>> backward_lines;
auto start_of_line = std::make_shared<Buffer::Iterator>(*m_iterator);
start_of_line->go_start_of_line();
@@ -93,6 +95,34 @@ void BufferView::update()
}
}
/**************************************************************************
* Internal functions
*************************************************************************/
int BufferView::determine_new_cursor_screen_row()
{
if (m_lines.size() > 0)
{
if (m_iterator->line() < m_lines.begin()->line->line())
{
return 0;
}
if (m_iterator->line() > m_lines.rbegin()->line->line())
{
return m_height;
}
for (const LineDescriptor & screen_line : m_lines)
{
if (screen_line.line->line() == m_iterator->line())
{
calculate_rows_in_cursor_line(screen_line.line);
return screen_line.row_offset + m_cursor_row_offset;
}
}
}
return 0;
}
int BufferView::calculate_rows_in_line(std::shared_ptr<Buffer::Iterator> start_of_line)
{
int saved_row_offset = 0;
+1
View File
@@ -89,6 +89,7 @@ protected:
{
return std::min(m_scroll_offset, (m_height - 1) / 2);
}
int determine_new_cursor_screen_row();
int calculate_rows_in_line(std::shared_ptr<Buffer::Iterator> start_of_line);
int calculate_rows_in_cursor_line(std::shared_ptr<Buffer::Iterator> start_of_line);
int screen_rows_below_line(std::shared_ptr<Buffer::Iterator> line);