diff --git a/src/gui/BufferPane.cc b/src/gui/BufferPane.cc index 3b543bf..7c80361 100644 --- a/src/gui/BufferPane.cc +++ b/src/gui/BufferPane.cc @@ -480,7 +480,7 @@ void BufferPane::redo() void BufferPane::delete_motion(const Command::Unit & motion) { - std::shared_ptr range = get_range_for_motion(motion); + auto range = get_range_for_motion(motion, false); if (range) { m_buffer->erase_range(*range); @@ -488,7 +488,20 @@ void BufferPane::delete_motion(const Command::Unit & motion) } } -std::shared_ptr 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 BufferPane::get_range_for_motion(const Command::Unit & motion, bool will_insert) { if (!m_iterator->valid()) { @@ -532,7 +545,7 @@ std::shared_ptr BufferPane::get_range_for_motion(const Command::U case Command::Motion::THIS_LINE: start->go_start_of_line(); - end->go_end_of_line(true); + end->go_end_of_line(!will_insert); end->go_forward(); break; diff --git a/src/gui/BufferPane.h b/src/gui/BufferPane.h index 62f2f8f..5c79edc 100644 --- a/src/gui/BufferPane.h +++ b/src/gui/BufferPane.h @@ -43,6 +43,7 @@ public: void undo(); void redo(); void delete_motion(const Command::Unit & motion); + void change_motion(const Command::Unit & motion); void set_show_status_bar(bool show_status_bar) { m_show_status_bar = show_status_bar; @@ -78,7 +79,7 @@ protected: void draw_status_bar(); int calculate_lines_to_scroll(Window::ScrollMode scroll_mode); void resize_buffer_view(); - std::shared_ptr get_range_for_motion(const Command::Unit & motion); + std::shared_ptr get_range_for_motion(const Command::Unit & motion, bool will_insert); Window * m_window; std::shared_ptr m_buffer; diff --git a/src/gui/Window.cc b/src/gui/Window.cc index 76f69a0..96f6fb4 100644 --- a/src/gui/Window.cc +++ b/src/gui/Window.cc @@ -352,8 +352,14 @@ void Window::execute_command(const Command & command) m_focused_buffer_pane->kill_character_backward(); break; case Command::CHANGE_MOTION: + m_focused_buffer_pane->change_motion(command.motion); break; case Command::CHANGE_LINE: + { + Command::Unit motion = command.motion; + motion.id = Command::Motion::THIS_LINE; + m_focused_buffer_pane->change_motion(motion); + } break; case Command::YANK_MOTION: break;