mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 06:27:45 +00:00
VimEditingEngine: Add P command to put before cursor
This commit is contained in:
parent
180e2469af
commit
c1e2710a0d
2 changed files with 21 additions and 3 deletions
|
@ -926,6 +926,8 @@ bool VimEditingEngine::on_key_in_normal_mode(const KeyEvent& event)
|
||||||
move_one_left();
|
move_one_left();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
case (KeyCode::Key_P):
|
||||||
|
put_before();
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -986,7 +988,7 @@ bool VimEditingEngine::on_key_in_normal_mode(const KeyEvent& event)
|
||||||
m_previous_key = event.key();
|
m_previous_key = event.key();
|
||||||
return true;
|
return true;
|
||||||
case (KeyCode::Key_P):
|
case (KeyCode::Key_P):
|
||||||
put();
|
put_after();
|
||||||
return true;
|
return true;
|
||||||
case (KeyCode::Key_PageUp):
|
case (KeyCode::Key_PageUp):
|
||||||
move_page_up();
|
move_page_up();
|
||||||
|
@ -1237,7 +1239,22 @@ void VimEditingEngine::yank(TextRange range)
|
||||||
m_yank_buffer = m_editor->document().text_in_range(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) {
|
if (m_yank_type == YankType::Line) {
|
||||||
move_to_logical_line_end();
|
move_to_logical_line_end();
|
||||||
|
|
|
@ -166,7 +166,8 @@ private:
|
||||||
String m_yank_buffer {};
|
String m_yank_buffer {};
|
||||||
void yank(YankType);
|
void yank(YankType);
|
||||||
void yank(TextRange);
|
void yank(TextRange);
|
||||||
void put();
|
void put_before();
|
||||||
|
void put_after();
|
||||||
|
|
||||||
TextPosition m_selection_start_position = {};
|
TextPosition m_selection_start_position = {};
|
||||||
void update_selection_on_cursor_move();
|
void update_selection_on_cursor_move();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue