add BufferPane::determine_new_cursor_screen_row() to allow the cursor to move properly within the screen
This commit is contained in:
parent
83a6c1a983
commit
e21c24e2cc
@ -145,6 +145,31 @@ int BufferPane::update_cursor_row(std::list<std::pair<int, Buffer::Iterator>> &
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ protected:
|
||||
int screen_rows_above_line(const Buffer::Iterator & line, std::list<std::pair<int, Buffer::Iterator>> & backward_lines);
|
||||
int update_cursor_row(std::list<std::pair<int, Buffer::Iterator>> & backward_lines);
|
||||
void walk_line(const Buffer::Iterator & start_of_line, std::function<void(int, int, int, int, const Buffer::Iterator &)> callback);
|
||||
int determine_new_cursor_screen_row();
|
||||
int col_x(int col)
|
||||
{
|
||||
return col * m_window->font()->get_advance();
|
||||
|
Loading…
x
Reference in New Issue
Block a user