diff --git a/src/gui/BufferPane.cc b/src/gui/BufferPane.cc index 3e438fb..2729edd 100644 --- a/src/gui/BufferPane.cc +++ b/src/gui/BufferPane.cc @@ -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()) diff --git a/src/gui/BufferPane.h b/src/gui/BufferPane.h index 57e5a4d..c9085ff 100644 --- a/src/gui/BufferPane.h +++ b/src/gui/BufferPane.h @@ -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();