add two more BufferPane utility functions to calculate available screen rows before and after the cursor line

This commit is contained in:
Josh Holtrop 2016-12-20 23:07:00 -05:00
parent cf4723854e
commit 975b7763a8
2 changed files with 24 additions and 29 deletions

View File

@ -25,33 +25,6 @@ void BufferPane::update_cursor_row()
int min_rows_to_leave_below = std::min(rows_below, so);
m_cursor_row = std::max(min_rows_to_leave_above, std::min(m_rows - min_rows_to_leave_below - 1, m_cursor_row));
}
int BufferPane::screen_rows_below_cursor(int stop_at)
{
Buffer::Cursor cursor = *m_cursor;
size_t column = cursor.column();
cursor.go_end_of_line(false);
int rows = (cursor.column() / m_columns) - (column / m_columns);
while ((rows < stop_at) && cursor.go_down(0u))
{
cursor.go_end_of_line(false);
rows += (cursor.column() / m_columns) + 1;
}
return rows;
}
int BufferPane::screen_rows_above_cursor(int stop_at)
{
Buffer::Cursor cursor = *m_cursor;
int rows = cursor.column() / m_columns;
while ((rows < stop_at) && cursor.go_up(0u))
{
Buffer::Cursor cursor2 = cursor;
cursor2.go_end_of_line(false);
rows += (cursor2.column() / m_columns) + 1;
}
return rows;
}
#endif
int BufferPane::rows_in_line(const Buffer::Iterator & start_of_line)
@ -116,6 +89,28 @@ int BufferPane::rows_in_line_with_iterator_offset(const Buffer::Iterator & start
return rows;
}
int BufferPane::screen_rows_below_line(const Buffer::Iterator & line)
{
Buffer::Iterator i = line;
int rows = 0;
while ((rows < m_rows) && i.go_next_line());
{
rows += rows_in_line(i);
}
return rows;
}
int BufferPane::screen_rows_above_line(const Buffer::Iterator & line)
{
Buffer::Iterator i = line;
int rows = 0;
while ((rows < m_rows) && i.go_previous_line())
{
rows += rows_in_line(i);
}
return rows;
}
void BufferPane::draw()
{
if (m_iterator->valid())

View File

@ -32,8 +32,6 @@ protected:
{
return std::min(m_scroll_offset, (m_rows - 1) / 2);
}
int screen_rows_below_cursor(int stop_at);
int screen_rows_above_cursor(int stop_at);
void update_cursor_row();
void draw_buffer_line(int screen_row, const Buffer::Cursor & cursor);
#endif
@ -42,6 +40,8 @@ protected:
void draw_cursor(int x, int y, bool insert_mode);
int rows_in_line(const Buffer::Iterator & start_of_line);
int rows_in_line_with_iterator_offset(const Buffer::Iterator & start_of_line, const Buffer::Iterator & reference, int * iterator_row_offset);
int screen_rows_below_line(const Buffer::Iterator & line);
int screen_rows_above_line(const Buffer::Iterator & line);
int col_x(int col)
{
return col * m_window->font()->get_advance();