BufferView: Use Buffer::Iterator functions for moving forward/backward in line

This commit is contained in:
Josh Holtrop 2017-11-21 22:09:53 -05:00
parent 3c6b3bc49e
commit e8267b765b
2 changed files with 4 additions and 82 deletions

View File

@ -164,16 +164,16 @@ bool BufferView::cursor_move(CursorMovement which, uint32_t c, bool allow_eol)
moved = move_cursor_screen_row_down(allow_eol); moved = move_cursor_screen_row_down(allow_eol);
break; break;
case CursorMovement::FORWARD_UP_TO_CHAR: case CursorMovement::FORWARD_UP_TO_CHAR:
moved = move_cursor_forward_up_to_char(c); moved = m_iterator->go_forward_in_line_up_to_char(c);
break; break;
case CursorMovement::FORWARD_ON_TO_CHAR: case CursorMovement::FORWARD_ON_TO_CHAR:
moved = move_cursor_forward_on_to_char(c); moved = m_iterator->go_forward_in_line_on_to_char(c);
break; break;
case CursorMovement::BACK_UP_TO_CHAR: case CursorMovement::BACK_UP_TO_CHAR:
moved = move_cursor_backward_up_to_char(c); moved = m_iterator->go_backward_in_line_up_to_char(c);
break; break;
case CursorMovement::BACK_ON_TO_CHAR: case CursorMovement::BACK_ON_TO_CHAR:
moved = move_cursor_backward_on_to_char(c); moved = m_iterator->go_backward_in_line_on_to_char(c);
break; break;
} }
if (moved) if (moved)
@ -446,80 +446,6 @@ void BufferView::move_forward_to_screen_position(
} }
} }
bool BufferView::move_cursor_forward_up_to_char(uint32_t c)
{
Buffer::Iterator last_it = *m_iterator;
Buffer::Iterator it = *m_iterator;
while (it.go_right_in_line(false))
{
if (*it == c)
{
if (last_it != *m_iterator)
{
*m_iterator = last_it;
return true;
}
else
{
return false;
}
}
last_it = it;
}
return false;
}
bool BufferView::move_cursor_forward_on_to_char(uint32_t c)
{
Buffer::Iterator it = *m_iterator;
while (it.go_right_in_line(false))
{
if (*it == c)
{
*m_iterator = it;
return true;
}
}
return false;
}
bool BufferView::move_cursor_backward_up_to_char(uint32_t c)
{
Buffer::Iterator last_it = *m_iterator;
Buffer::Iterator it = *m_iterator;
while (it.go_left_in_line())
{
if (*it == c)
{
if (last_it != *m_iterator)
{
*m_iterator = last_it;
return true;
}
else
{
return false;
}
}
last_it = it;
}
return false;
}
bool BufferView::move_cursor_backward_on_to_char(uint32_t c)
{
Buffer::Iterator it = *m_iterator;
while (it.go_left_in_line())
{
if (*it == c)
{
*m_iterator = it;
return true;
}
}
return false;
}
int BufferView::calculate_rows_above_screen(int stop_at) int BufferView::calculate_rows_above_screen(int stop_at)
{ {
if (m_lines.empty()) if (m_lines.empty())

View File

@ -132,10 +132,6 @@ protected:
void move_forward_to_screen_position( void move_forward_to_screen_position(
std::shared_ptr<Buffer::Iterator> line, int target_row_offset, std::shared_ptr<Buffer::Iterator> line, int target_row_offset,
bool allow_eol); bool allow_eol);
bool move_cursor_forward_up_to_char(uint32_t c);
bool move_cursor_forward_on_to_char(uint32_t c);
bool move_cursor_backward_up_to_char(uint32_t c);
bool move_cursor_backward_on_to_char(uint32_t c);
int calculate_rows_above_screen(int stop_at); int calculate_rows_above_screen(int stop_at);
int calculate_rows_below_screen(int stop_at); int calculate_rows_below_screen(int stop_at);
}; };