VimEditingEngine: Add P command to put before cursor

This commit is contained in:
Matthew Hall 2021-07-10 22:24:03 +01:00 committed by Gunnar Beutner
parent 180e2469af
commit c1e2710a0d
Notes: sideshowbarker 2024-07-18 08:59:24 +09:00
2 changed files with 21 additions and 3 deletions

View file

@ -926,6 +926,8 @@ bool VimEditingEngine::on_key_in_normal_mode(const KeyEvent& event)
move_one_left();
return true;
}
case (KeyCode::Key_P):
put_before();
default:
break;
}
@ -986,7 +988,7 @@ bool VimEditingEngine::on_key_in_normal_mode(const KeyEvent& event)
m_previous_key = event.key();
return true;
case (KeyCode::Key_P):
put();
put_after();
return true;
case (KeyCode::Key_PageUp):
move_page_up();
@ -1237,7 +1239,22 @@ void VimEditingEngine::yank(TextRange range)
m_yank_buffer = m_editor->document().text_in_range(range);
}
void VimEditingEngine::put()
void VimEditingEngine::put_before()
{
if (m_yank_type == YankType::Line) {
move_to_logical_line_beginning();
StringBuilder sb = StringBuilder(m_yank_buffer.length() + 1);
sb.append(m_yank_buffer);
sb.append_code_point(0x0A);
m_editor->insert_at_cursor_or_replace_selection(sb.to_string());
m_editor->set_cursor({ m_editor->cursor().line(), m_editor->current_line().first_non_whitespace_column() });
} else {
m_editor->insert_at_cursor_or_replace_selection(m_yank_buffer);
move_one_left();
}
}
void VimEditingEngine::put_after()
{
if (m_yank_type == YankType::Line) {
move_to_logical_line_end();

View file

@ -166,7 +166,8 @@ private:
String m_yank_buffer {};
void yank(YankType);
void yank(TextRange);
void put();
void put_before();
void put_after();
TextPosition m_selection_start_position = {};
void update_selection_on_cursor_move();