From 183f32803b6495a716e85d643f19dbacde4ed053 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 3 Jun 2018 14:10:07 +1000 Subject: [PATCH] Fix selection save/restore from registers post selection list syntax change --- src/normal.cc | 23 ++++++++++------------- test/normal/restore-selections/cmd | 1 + test/normal/restore-selections/in | 1 + test/normal/restore-selections/selections | 1 + 4 files changed, 13 insertions(+), 13 deletions(-) create mode 100644 test/normal/restore-selections/cmd create mode 100644 test/normal/restore-selections/in create mode 100644 test/normal/restore-selections/selections diff --git a/src/normal.cc b/src/normal.cc index c35ee87f..eeac76f2 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -1730,19 +1730,16 @@ SelectionList read_selections_from_register(char reg, Context& context) if (content.size() != 1) throw runtime_error(format("register '{}' does not contain a selections desc", reg)); - StringView desc = content[0]; - auto arobase = find(desc, '@'); - auto percent = find(desc, '%'); - - if (arobase == desc.end() or percent == desc.end()) + auto splitted = content[0] | split(' '); + if (splitted.begin() == splitted.end()) throw runtime_error(format("register '{}' does not contain a selections desc", reg)); - Buffer& buffer = BufferManager::instance().get_buffer({arobase+1, percent}); - size_t timestamp = str_to_int({percent + 1, desc.end()}); + struct error : runtime_error { error(size_t) : runtime_error{"expected @"} {} }; + const auto buffer_desc = *splitted.begin() | split('@') | static_gather(); + Buffer& buffer = BufferManager::instance().get_buffer(buffer_desc[0]); + const size_t timestamp = str_to_int(buffer_desc[1]); - auto sels = StringView{desc.begin(), arobase} | split(':') - | transform(selection_from_string) - | gather>(); + auto sels = splitted | skip(1) | transform(selection_from_string) | gather>(); if (sels.empty()) throw runtime_error(format("register '{}' contains an empty selection list", reg)); @@ -1860,9 +1857,9 @@ void save_selections(Context& context, NormalParams params) const bool empty = content.size() == 1 and content[0].empty(); auto save_to_reg = [reg](Context& context, const SelectionList& sels) { - String desc = format("{}@{}%{}", selection_list_to_string(sels), - context.buffer().name(), - context.buffer().timestamp()); + String desc = format("{}@{} {}", context.buffer().name(), + context.buffer().timestamp(), + selection_list_to_string(sels)); RegisterManager::instance()[reg].set(context, desc); context.print_status({format("{} {} selections to register '{}'", combine ? "Combined" : "Saved", sels.size(), reg), diff --git a/test/normal/restore-selections/cmd b/test/normal/restore-selections/cmd new file mode 100644 index 00000000..7c426e79 --- /dev/null +++ b/test/normal/restore-selections/cmd @@ -0,0 +1 @@ +Zz diff --git a/test/normal/restore-selections/in b/test/normal/restore-selections/in new file mode 100644 index 00000000..478a6fee --- /dev/null +++ b/test/normal/restore-selections/in @@ -0,0 +1 @@ +%(foo) %(bar) %(baz) diff --git a/test/normal/restore-selections/selections b/test/normal/restore-selections/selections new file mode 100644 index 00000000..45d79f3b --- /dev/null +++ b/test/normal/restore-selections/selections @@ -0,0 +1 @@ +'foo' 'bar' 'baz'