From 937bef69d9ee5e923cde1bde8ce1b6e1257b9a9d Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 7 Dec 2015 13:43:09 +0000 Subject: [PATCH] Add support for adding saved selections to current ones with --- README.asciidoc | 1 + src/normal.cc | 25 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/README.asciidoc b/README.asciidoc index 179256e2..bdfe4529 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -432,6 +432,7 @@ using `"` prefix. `Z` will save the current selections to the register. `z` will restore the selections from the register. +`alt-z` will add the selections from the register to the existing ones. Jump list ~~~~~~~~~ diff --git a/src/normal.cc b/src/normal.cc index 24f5e1c9..839093ac 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -1321,6 +1321,7 @@ void save_selections(Context& context, NormalParams params) context.print_status({format("Saved selections in register '{}'", reg), get_face("Information")}); } +template void restore_selections(Context& context, NormalParams params) { const char reg = to_lower(params.reg ? params.reg : '^'); @@ -1348,11 +1349,26 @@ void restore_selections(Context& context, NormalParams params) SelectionList sel_list{buffer, std::move(sels), timestamp}; - if (&buffer != &context.buffer()) - context.change_buffer(buffer); + if (not add) + { + if (&buffer != &context.buffer()) + context.change_buffer(buffer); + } + else + { + if (&buffer != &context.buffer()) + throw runtime_error("Cannot add selections from another buffer"); + + sel_list.update(); + int main_index = sel_list.size() + context.selections_write_only().main_index(); + for (auto& sel : context.selections()) + sel_list.push_back(std::move(sel)); + + sel_list.set_main_index(main_index); + sel_list.sort_and_merge_overlapping(); + } context.selections_write_only() = std::move(sel_list); - context.print_status({format("Restored selections from register '{}'", reg), get_face("Information")}); } @@ -1671,7 +1687,8 @@ static NormalCmdDesc cmds[] = { Key::PageUp, "scroll one page up", scroll }, { Key::PageDown, "scroll one page down", scroll }, - { 'z', "restore selections", restore_selections }, + { 'z', "restore selections", restore_selections }, + { alt('z'), "append saved selections", restore_selections }, { 'Z', "save selections", save_selections }, };