mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
VimEditingEngine: Add support for repeats of p and P
This commit is contained in:
parent
7b7548ce9d
commit
2653ad36ee
Notes:
sideshowbarker
2024-07-18 08:59:17 +09:00
Author: https://github.com/mattyhall Commit: https://github.com/SerenityOS/serenity/commit/2653ad36ee3 Pull-request: https://github.com/SerenityOS/serenity/pull/8622
1 changed files with 23 additions and 7 deletions
|
@ -1295,33 +1295,49 @@ void VimEditingEngine::yank(TextRange range, YankType yank_type)
|
|||
|
||||
void VimEditingEngine::put_before()
|
||||
{
|
||||
auto amount = m_motion.amount() ? m_motion.amount() : 1;
|
||||
m_motion.reset();
|
||||
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);
|
||||
StringBuilder sb = StringBuilder(amount * (m_yank_buffer.length() + 1));
|
||||
for (auto i = 0; i < amount; i++) {
|
||||
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);
|
||||
StringBuilder sb = StringBuilder(m_yank_buffer.length() * amount);
|
||||
for (auto i = 0; i < amount; i++) {
|
||||
sb.append(m_yank_buffer);
|
||||
}
|
||||
m_editor->insert_at_cursor_or_replace_selection(sb.to_string());
|
||||
move_one_left();
|
||||
}
|
||||
}
|
||||
|
||||
void VimEditingEngine::put_after()
|
||||
{
|
||||
auto amount = m_motion.amount() ? m_motion.amount() : 1;
|
||||
m_motion.reset();
|
||||
if (m_yank_type == YankType::Line) {
|
||||
move_to_logical_line_end();
|
||||
StringBuilder sb = StringBuilder(m_yank_buffer.length() + 1);
|
||||
sb.append_code_point(0x0A);
|
||||
sb.append(m_yank_buffer);
|
||||
for (auto i = 0; i < amount; i++) {
|
||||
sb.append_code_point(0x0A);
|
||||
sb.append(m_yank_buffer);
|
||||
}
|
||||
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 {
|
||||
// FIXME: If attempting to put on the last column a line,
|
||||
// the buffer will bne placed on the next line due to the move_one_left/right behaviour.
|
||||
move_one_right();
|
||||
m_editor->insert_at_cursor_or_replace_selection(m_yank_buffer);
|
||||
StringBuilder sb = StringBuilder(m_yank_buffer.length() * amount);
|
||||
for (auto i = 0; i < amount; i++) {
|
||||
sb.append(m_yank_buffer);
|
||||
}
|
||||
m_editor->insert_at_cursor_or_replace_selection(sb.to_string());
|
||||
move_one_left();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue