Implement f/F/t/T commands

This commit is contained in:
Josh Holtrop 2017-11-15 21:01:20 -05:00
parent 917491c08b
commit bb5bf6a13a
3 changed files with 102 additions and 0 deletions

View File

@ -163,6 +163,18 @@ bool BufferView::cursor_move(CursorMovement which, uint32_t c, bool allow_eol)
case CursorMovement::SCREEN_ROW_DOWN:
moved = move_cursor_screen_row_down(allow_eol);
break;
case CursorMovement::FORWARD_UP_TO_CHAR:
moved = move_cursor_forward_up_to_char(c);
break;
case CursorMovement::FORWARD_ON_TO_CHAR:
moved = move_cursor_forward_on_to_char(c);
break;
case CursorMovement::BACK_UP_TO_CHAR:
moved = move_cursor_backward_up_to_char(c);
break;
case CursorMovement::BACK_ON_TO_CHAR:
moved = move_cursor_backward_on_to_char(c);
break;
}
if (moved)
{
@ -181,6 +193,10 @@ bool BufferView::cursor_move(CursorMovement which, uint32_t c, bool allow_eol)
break;
case CursorMovement::SOL:
case CursorMovement::EOL:
case CursorMovement::FORWARD_UP_TO_CHAR:
case CursorMovement::FORWARD_ON_TO_CHAR:
case CursorMovement::BACK_UP_TO_CHAR:
case CursorMovement::BACK_ON_TO_CHAR:
determine_new_cursor_screen_row();
break;
case CursorMovement::FIRST_LINE:
@ -430,6 +446,80 @@ 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)
{
if (m_lines.empty())

View File

@ -26,6 +26,10 @@ public:
LAST_LINE,
SCREEN_ROW_UP,
SCREEN_ROW_DOWN,
FORWARD_UP_TO_CHAR,
FORWARD_ON_TO_CHAR,
BACK_UP_TO_CHAR,
BACK_ON_TO_CHAR,
};
class Iterator
@ -128,6 +132,10 @@ protected:
void move_forward_to_screen_position(
std::shared_ptr<Buffer::Iterator> line, int target_row_offset,
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_below_screen(int stop_at);
};

View File

@ -324,12 +324,16 @@ void Window::execute_command(const Command & command)
switch (command.main.id)
{
case Command::GO_FORWARD_UP_TO_CHAR:
m_focused_buffer_pane->cursor_move(BufferPane::CursorMovement::FORWARD_UP_TO_CHAR, command.main.following_char);
break;
case Command::GO_FORWARD_ON_TO_CHAR:
m_focused_buffer_pane->cursor_move(BufferPane::CursorMovement::FORWARD_ON_TO_CHAR, command.main.following_char);
break;
case Command::GO_BACK_UP_TO_CHAR:
m_focused_buffer_pane->cursor_move(BufferPane::CursorMovement::BACK_UP_TO_CHAR, command.main.following_char);
break;
case Command::GO_BACK_ON_TO_CHAR:
m_focused_buffer_pane->cursor_move(BufferPane::CursorMovement::BACK_ON_TO_CHAR, command.main.following_char);
break;
case Command::DELETE_MOTION:
break;