summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorMatthew Hall <matthew@quickbeam.me.uk>2021-07-13 19:16:32 +0100
committerGunnar Beutner <gunnar@beutner.name>2021-07-15 10:10:07 +0200
commit2653ad36ee37587cd1378d2c51ed4c0b4b3cf24f (patch)
tree927abb3fc705e8f3ed8aa26c3a1b067c22f8bca9 /Userland/Libraries
parent7b7548ce9db9a282d70436a199c2e4d788dee2ab (diff)
downloadserenity-2653ad36ee37587cd1378d2c51ed4c0b4b3cf24f.zip
VimEditingEngine: Add support for repeats of p and P
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibGUI/VimEditingEngine.cpp30
1 files changed, 23 insertions, 7 deletions
diff --git a/Userland/Libraries/LibGUI/VimEditingEngine.cpp b/Userland/Libraries/LibGUI/VimEditingEngine.cpp
index 34de80c697..be97b90893 100644
--- a/Userland/Libraries/LibGUI/VimEditingEngine.cpp
+++ b/Userland/Libraries/LibGUI/VimEditingEngine.cpp
@@ -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();
}
}