Implement several change commands

This commit is contained in:
Josh Holtrop 2017-11-24 12:55:08 -05:00
parent 0fcc3d3c68
commit 05f745d3f2
3 changed files with 24 additions and 4 deletions

View File

@ -480,7 +480,7 @@ void BufferPane::redo()
void BufferPane::delete_motion(const Command::Unit & motion) void BufferPane::delete_motion(const Command::Unit & motion)
{ {
std::shared_ptr<Buffer::Range> range = get_range_for_motion(motion); auto range = get_range_for_motion(motion, false);
if (range) if (range)
{ {
m_buffer->erase_range(*range); m_buffer->erase_range(*range);
@ -488,7 +488,20 @@ void BufferPane::delete_motion(const Command::Unit & motion)
} }
} }
std::shared_ptr<Buffer::Range> BufferPane::get_range_for_motion(const Command::Unit & motion) void BufferPane::change_motion(const Command::Unit & motion)
{
auto range = get_range_for_motion(motion, true);
if (range)
{
m_buffer->push_operation();
m_buffer->erase_range(*range);
enter_insert_mode(Window::EnterInsertModeMode::START_OF_CHAR);
m_buffer->pop_operation();
m_buffer_view->update();
}
}
std::shared_ptr<Buffer::Range> BufferPane::get_range_for_motion(const Command::Unit & motion, bool will_insert)
{ {
if (!m_iterator->valid()) if (!m_iterator->valid())
{ {
@ -532,7 +545,7 @@ std::shared_ptr<Buffer::Range> BufferPane::get_range_for_motion(const Command::U
case Command::Motion::THIS_LINE: case Command::Motion::THIS_LINE:
start->go_start_of_line(); start->go_start_of_line();
end->go_end_of_line(true); end->go_end_of_line(!will_insert);
end->go_forward(); end->go_forward();
break; break;

View File

@ -43,6 +43,7 @@ public:
void undo(); void undo();
void redo(); void redo();
void delete_motion(const Command::Unit & motion); void delete_motion(const Command::Unit & motion);
void change_motion(const Command::Unit & motion);
void set_show_status_bar(bool show_status_bar) void set_show_status_bar(bool show_status_bar)
{ {
m_show_status_bar = show_status_bar; m_show_status_bar = show_status_bar;
@ -78,7 +79,7 @@ protected:
void draw_status_bar(); void draw_status_bar();
int calculate_lines_to_scroll(Window::ScrollMode scroll_mode); int calculate_lines_to_scroll(Window::ScrollMode scroll_mode);
void resize_buffer_view(); void resize_buffer_view();
std::shared_ptr<Buffer::Range> get_range_for_motion(const Command::Unit & motion); std::shared_ptr<Buffer::Range> get_range_for_motion(const Command::Unit & motion, bool will_insert);
Window * m_window; Window * m_window;
std::shared_ptr<Buffer> m_buffer; std::shared_ptr<Buffer> m_buffer;

View File

@ -352,8 +352,14 @@ void Window::execute_command(const Command & command)
m_focused_buffer_pane->kill_character_backward(); m_focused_buffer_pane->kill_character_backward();
break; break;
case Command::CHANGE_MOTION: case Command::CHANGE_MOTION:
m_focused_buffer_pane->change_motion(command.motion);
break; break;
case Command::CHANGE_LINE: case Command::CHANGE_LINE:
{
Command::Unit motion = command.motion;
motion.id = Command::Motion::THIS_LINE;
m_focused_buffer_pane->change_motion(motion);
}
break; break;
case Command::YANK_MOTION: case Command::YANK_MOTION:
break; break;