From 7a5b58e8a8d68c1941d5ffbe69b63b3500346ed3 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sun, 1 Jan 2017 20:58:08 -0500 Subject: [PATCH] BufferPane: rename functions to calculate rows in lines --- src/gui/BufferPane.cc | 31 ++++++++++++++++++++++++------- src/gui/BufferPane.h | 5 +++-- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/gui/BufferPane.cc b/src/gui/BufferPane.cc index 4133407..dd0a035 100644 --- a/src/gui/BufferPane.cc +++ b/src/gui/BufferPane.cc @@ -74,7 +74,7 @@ void BufferPane::walk_line(const Buffer::Iterator & start_of_line, std::function } } -int BufferPane::rows_in_line(const Buffer::Iterator & start_of_line) +int BufferPane::calculate_rows_in_line(const Buffer::Iterator & start_of_line) { int saved_row_offset = 0; walk_line(start_of_line, [&saved_row_offset](int row_offset, int screen_column, int virtual_column, int character_width, const Buffer::Iterator & i) { @@ -87,7 +87,7 @@ int BufferPane::rows_in_line(const Buffer::Iterator & start_of_line) return saved_row_offset + 1; } -int BufferPane::rows_in_line_with_iterator_offset(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, const Buffer::Iterator & reference, int * iterator_row_offset) { 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) { @@ -105,13 +105,30 @@ int BufferPane::rows_in_line_with_iterator_offset(const Buffer::Iterator & start return saved_row_offset + 1; } +int BufferPane::calculate_rows_in_line_with_iterator_offset(const Buffer::Iterator & start_of_line, const Buffer::Iterator & reference, int * iterator_row_offset) +{ + 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) { + uint32_t code_point = *i; + if (i == reference) + { + *iterator_row_offset = row_offset; + } + if ((code_point != '\n') && (code_point != Buffer::Iterator::INVALID_CODE_POINT)) + { + saved_row_offset = row_offset; + } + }); + return saved_row_offset + 1; +} + 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); + rows += calculate_rows_in_line(i); } return rows; } @@ -122,7 +139,7 @@ int BufferPane::screen_rows_above_line(const Buffer::Iterator & line, std::list< int rows = 0; while ((rows < m_rows) && i.go_previous_line()) { - int rows_in_this_line = rows_in_line(i); + int rows_in_this_line = calculate_rows_in_line(i); rows += rows_in_this_line; backward_lines.push_back(std::pair(rows_in_this_line, i)); } @@ -134,7 +151,7 @@ int BufferPane::update_cursor_row(std::list> & Buffer::Iterator start_of_line = *m_iterator; start_of_line.go_start_of_line(); int cursor_row_offset; - int rows_in_cursor_line = rows_in_line_with_iterator_offset(start_of_line, *m_iterator, &cursor_row_offset); + int rows_in_cursor_line = calculate_rows_in_cursor_line(start_of_line, *m_iterator, &cursor_row_offset); 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); @@ -164,7 +181,7 @@ int BufferPane::determine_new_cursor_screen_row() if (screen_line.second.line() == m_iterator->line()) { int row_offset; - rows_in_line_with_iterator_offset(screen_line.second, *m_iterator, &row_offset); + calculate_rows_in_cursor_line(screen_line.second, *m_iterator, &row_offset); return screen_line.first + row_offset; } } @@ -452,7 +469,7 @@ void BufferPane::cursor_move(Window::CursorMovement which) int cursor_row_offset; Buffer::Iterator start_of_line = *m_iterator; start_of_line.go_start_of_line(); - rows_in_line_with_iterator_offset(start_of_line, *m_iterator, &cursor_row_offset); + calculate_rows_in_cursor_line(start_of_line, *m_iterator, &cursor_row_offset); m_target_column = m_cursor_virtual_column; } break; diff --git a/src/gui/BufferPane.h b/src/gui/BufferPane.h index fa8d6e7..fdcb349 100644 --- a/src/gui/BufferPane.h +++ b/src/gui/BufferPane.h @@ -32,8 +32,9 @@ protected: int character_width(uint32_t character); void draw_buffer_character(int screen_column, int screen_row, uint32_t character); void draw_cursor(int x, int y); - 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 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_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);