diff --git a/src/gui/BufferPane.cc b/src/gui/BufferPane.cc index 55a8d37..3e438fb 100644 --- a/src/gui/BufferPane.cc +++ b/src/gui/BufferPane.cc @@ -54,12 +54,72 @@ int BufferPane::screen_rows_above_cursor(int stop_at) } #endif +int BufferPane::rows_in_line(const Buffer::Iterator & start_of_line) +{ + int rows = 1; + int screen_column = 0; + Buffer::Iterator i = start_of_line; + for (;;) + { + uint32_t code_point = *i; + if ((code_point == '\n') || (!i.valid())) + { + break; + } + int c_width = character_width(code_point); + if (((screen_column + c_width) > m_columns) && + (c_width <= m_columns)) + { + rows++; + screen_column = c_width; + } + else + { + screen_column += c_width; + } + } + return rows; +} + +int BufferPane::rows_in_line_with_iterator_offset(const Buffer::Iterator & start_of_line, const Buffer::Iterator & reference, int * iterator_row_offset) +{ + int rows = 1; + int screen_column = 0; + Buffer::Iterator i = start_of_line; + for (;;) + { + uint32_t code_point = *i; + if ((code_point == '\n') || (!i.valid())) + { + if (screen_column == m_columns) + { + *iterator_row_offset = rows; + } + else + { + *iterator_row_offset = rows - 1; + } + break; + } + int c_width = character_width(code_point); + if (((screen_column + c_width) > m_columns) && + (c_width <= m_columns)) + { + rows++; + screen_column = c_width; + } + else + { + screen_column += c_width; + } + } + return rows; +} + void BufferPane::draw() { if (m_iterator->valid()) { - Buffer::Iterator i = *m_iterator; - i.go_start_of_line(); #if 0 update_cursor_row(); int screen_row = m_cursor_row - m_cursor->column() / m_columns; diff --git a/src/gui/BufferPane.h b/src/gui/BufferPane.h index a537b09..57e5a4d 100644 --- a/src/gui/BufferPane.h +++ b/src/gui/BufferPane.h @@ -40,6 +40,8 @@ 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, 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 col_x(int col) { return col * m_window->font()->get_advance();