mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-24 18:24:45 -05:00
VimEditingEngine: Add P command to put before cursor
This commit is contained in:
parent
180e2469af
commit
c1e2710a0d
Notes:
sideshowbarker
2024-07-18 08:59:24 +09:00
Author: https://github.com/mattyhall Commit: https://github.com/SerenityOS/serenity/commit/c1e2710a0d7 Pull-request: https://github.com/SerenityOS/serenity/pull/8622
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();
|
||||
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();
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Reference in a new issue