diff --git a/src/gui/BufferPane.cc b/src/gui/BufferPane.cc index dd0a035..7928533 100644 --- a/src/gui/BufferPane.cc +++ b/src/gui/BufferPane.cc @@ -87,15 +87,16 @@ int BufferPane::calculate_rows_in_line(const Buffer::Iterator & start_of_line) return saved_row_offset + 1; } -int BufferPane::calculate_rows_in_cursor_line(const Buffer::Iterator & start_of_line, const Buffer::Iterator & reference, int * iterator_row_offset) +int BufferPane::calculate_rows_in_cursor_line(const Buffer::Iterator & start_of_line) { int saved_row_offset = 0; - walk_line(start_of_line, [this, &saved_row_offset, &reference, &iterator_row_offset](int row_offset, int screen_column, int virtual_column, int character_width, const Buffer::Iterator & i) { + walk_line(start_of_line, [this, &saved_row_offset](int row_offset, int screen_column, int virtual_column, int character_width, const Buffer::Iterator & i) { uint32_t code_point = *i; - if (i == reference) + if (i == *m_iterator) { m_cursor_virtual_column = virtual_column; - *iterator_row_offset = row_offset; + m_cursor_screen_column = screen_column; + m_cursor_row_offset = row_offset; } if ((code_point != '\n') && (code_point != Buffer::Iterator::INVALID_CODE_POINT)) { @@ -146,22 +147,20 @@ int BufferPane::screen_rows_above_line(const Buffer::Iterator & line, std::list< return rows; } -int BufferPane::update_cursor_row(std::list> & backward_lines) +void BufferPane::update_cursor_row(std::list> & backward_lines) { Buffer::Iterator start_of_line = *m_iterator; start_of_line.go_start_of_line(); - int cursor_row_offset; - int rows_in_cursor_line = calculate_rows_in_cursor_line(start_of_line, *m_iterator, &cursor_row_offset); + int rows_in_cursor_line = calculate_rows_in_cursor_line(start_of_line); int so = effective_scroll_offset(); - int rows_above = screen_rows_above_line(*m_iterator, backward_lines) + cursor_row_offset; - int rows_below = screen_rows_below_line(*m_iterator) + std::max(0, rows_in_cursor_line - cursor_row_offset - 1); + int rows_above = screen_rows_above_line(*m_iterator, backward_lines) + m_cursor_row_offset; + int rows_below = screen_rows_below_line(*m_iterator) + std::max(0, rows_in_cursor_line - m_cursor_row_offset - 1); int min_rows_to_leave_above = std::min(rows_above, so); int min_rows_to_leave_below = std::min(rows_below, so); m_cursor_screen_row = std::min(m_rows - min_rows_to_leave_below - 1, m_cursor_screen_row); m_cursor_screen_row = std::max(min_rows_to_leave_above, m_cursor_screen_row); m_cursor_screen_row = std::max(m_rows - rows_below - 1, m_cursor_screen_row); m_cursor_screen_row = std::min(rows_above, m_cursor_screen_row); - return cursor_row_offset; } int BufferPane::determine_new_cursor_screen_row() @@ -180,9 +179,8 @@ int BufferPane::determine_new_cursor_screen_row() { if (screen_line.second.line() == m_iterator->line()) { - int row_offset; - calculate_rows_in_cursor_line(screen_line.second, *m_iterator, &row_offset); - return screen_line.first + row_offset; + calculate_rows_in_cursor_line(screen_line.second); + return screen_line.first + m_cursor_row_offset; } } } @@ -195,8 +193,8 @@ void BufferPane::draw() if (m_iterator->valid()) { std::list> backward_lines; - int cursor_row_offset_in_current_line = update_cursor_row(backward_lines); - int screen_row = m_cursor_screen_row - cursor_row_offset_in_current_line; + update_cursor_row(backward_lines); + int screen_row = m_cursor_screen_row - m_cursor_row_offset; Buffer::Iterator i = *m_iterator; if (screen_row <= 0) { @@ -466,10 +464,9 @@ void BufferPane::cursor_move(Window::CursorMovement which) case Window::CursorMovement::LEFT: case Window::CursorMovement::RIGHT: { - int cursor_row_offset; Buffer::Iterator start_of_line = *m_iterator; start_of_line.go_start_of_line(); - calculate_rows_in_cursor_line(start_of_line, *m_iterator, &cursor_row_offset); + calculate_rows_in_cursor_line(start_of_line); m_target_column = m_cursor_virtual_column; } break; diff --git a/src/gui/BufferPane.h b/src/gui/BufferPane.h index fdcb349..81cd5d8 100644 --- a/src/gui/BufferPane.h +++ b/src/gui/BufferPane.h @@ -33,11 +33,11 @@ protected: void draw_buffer_character(int screen_column, int screen_row, uint32_t character); void draw_cursor(int x, int y); int calculate_rows_in_line(const Buffer::Iterator & start_of_line); - int calculate_rows_in_cursor_line(const Buffer::Iterator & start_of_line, const Buffer::Iterator & reference, int * iterator_row_offset); + int calculate_rows_in_cursor_line(const Buffer::Iterator & start_of_line); int calculate_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, std::list> & backward_lines); - int update_cursor_row(std::list> & backward_lines); + void 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) @@ -59,7 +59,9 @@ protected: int m_columns; int m_scroll_offset; int m_cursor_screen_row; + int m_cursor_screen_column; int m_cursor_virtual_column; + int m_cursor_row_offset; std::shared_ptr m_iterator; std::list> m_screen_lines; int m_target_column;