From d181a40a91f87e1fb2490281947f07b2fcd071bc Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 3 Jul 2014 00:25:39 +0100 Subject: Add support for paste all (on ) Paste all pastes all yanked text at all selections, selecting each pasted text. Replace paste moves to R, and concat yank/concat delete (Y and D) are removed. Fixes #161 --- src/normal.cc | 65 +++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 26 deletions(-) (limited to 'src/normal.cc') diff --git a/src/normal.cc b/src/normal.cc index 5aaa79ae..4af47ada 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -446,17 +446,6 @@ void yank(Context& context, int) " selections", get_color("Information") }); } -void cat_yank(Context& context, int) -{ - auto sels = context.selections_content(); - String str; - for (auto& sel : sels) - str += sel; - RegisterManager::instance()['"'] = memoryview(str); - context.print_status({ "concatenated and yanked " + - to_string(sels.size()) + " selections", get_color("Information") }); -} - void erase_selections(Context& context, int) { RegisterManager::instance()['"'] = context.selections_content(); @@ -465,18 +454,6 @@ void erase_selections(Context& context, int) context.selections().avoid_eol(); } -void cat_erase_selections(Context& context, int) -{ - auto sels = context.selections_content(); - String str; - for (auto& sel : sels) - str += sel; - RegisterManager::instance()['"'] = memoryview(str); - context.selections().erase(); - context.selections().avoid_eol(); -} - - void change(Context& context, int param) { RegisterManager::instance()['"'] = context.selections_content(); @@ -510,6 +487,42 @@ void paste(Context& context, int) context.selections().insert(strings, effective_mode); } +template +void paste_all(Context& context, int) +{ + auto strings = RegisterManager::instance()['"'].values(context); + InsertMode effective_mode = mode; + String all; + std::vector offsets; + for (auto& str : strings) + { + if (not str.empty() and str.back() == '\n') + effective_mode = adapt_for_linewise(mode); + all += str; + offsets.push_back(all.length()); + } + + auto& selections = context.selections(); + { + ScopedEdition edition(context); + selections.insert(all, effective_mode, true); + } + + const Buffer& buffer = context.buffer(); + std::vector result; + for (auto& selection : selections) + { + ByteCount pos = 0; + for (auto offset : offsets) + { + result.push_back({ buffer.advance(selection.min(), pos), + buffer.advance(selection.min(), offset-1) }); + pos = offset; + } + } + selections = std::move(result); +} + template void regex_prompt(Context& context, const String prompt, T func) { @@ -1250,7 +1263,6 @@ KeyMap keymap = { alt('F'), select_to_next_char }, { 'd', erase_selections }, - { 'D', cat_erase_selections }, { 'c', change }, { 'i', enter_insert_mode }, { 'I', enter_insert_mode }, @@ -1266,10 +1278,11 @@ KeyMap keymap = { 'v', view_commands }, { 'y', yank }, - { 'Y', cat_yank }, { 'p', repeated(paste) }, { 'P', repeated(paste) }, - { alt('p'), paste }, + { alt('p'), paste_all }, + { alt('P'), paste_all }, + { 'R', paste }, { 's', select_regex }, { 'S', split_regex }, -- cgit v1.2.3