diff --git a/src/normal.cc b/src/normal.cc index eeac76f2..e66045a3 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -1727,23 +1727,18 @@ SelectionList read_selections_from_register(char reg, Context& context) auto content = RegisterManager::instance()[reg].get(context); - if (content.size() != 1) + if (content.size() < 2) throw runtime_error(format("register '{}' does not contain a selections desc", reg)); - auto splitted = content[0] | split(' '); - if (splitted.begin() == splitted.end()) - throw runtime_error(format("register '{}' does not contain a selections desc", reg)); + struct error : runtime_error { error(size_t) : runtime_error{"expected @@main_index"} {} }; + const auto desc = content[0] | split('@') | static_gather(); + Buffer& buffer = BufferManager::instance().get_buffer(desc[0]); + const size_t timestamp = str_to_int(desc[1]); + const size_t main = str_to_int(desc[2]); - 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 = content | skip(1) | 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)); - - return {SelectionList::UnsortedTag{}, buffer, std::move(sels), timestamp}; + return {SelectionList::UnsortedTag{}, buffer, std::move(sels), timestamp, main}; } enum class CombineOp @@ -1857,10 +1852,11 @@ 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("{}@{} {}", context.buffer().name(), - context.buffer().timestamp(), - selection_list_to_string(sels)); - RegisterManager::instance()[reg].set(context, desc); + auto& buffer = context.buffer(); + auto descs = concatenated(ConstArrayView{format("{}@{}@{}", buffer.name(), buffer.timestamp(), sels.main_index())}, + sels | transform(selection_to_string)) | gather>(); + RegisterManager::instance()[reg].set(context, descs); + context.print_status({format("{} {} selections to register '{}'", combine ? "Combined" : "Saved", sels.size(), reg), context.faces()["Information"]}); diff --git a/src/selection.cc b/src/selection.cc index 1cd8641c..02358fea 100644 --- a/src/selection.cc +++ b/src/selection.cc @@ -27,10 +27,7 @@ SelectionList::SelectionList(Buffer& buffer, Vector list, size_t time SelectionList::SelectionList(Buffer& buffer, Vector list) : SelectionList(buffer, std::move(list), buffer.timestamp()) {} -SelectionList::SelectionList(SelectionList::UnsortedTag, Buffer& buffer, Vector list) - : SelectionList(UnsortedTag{}, buffer, std::move(list), buffer.timestamp()) {} - -SelectionList::SelectionList(SelectionList::UnsortedTag, Buffer& buffer, Vector list, size_t timestamp) +SelectionList::SelectionList(SelectionList::UnsortedTag, Buffer& buffer, Vector list, size_t timestamp, size_t main) : m_buffer(&buffer), m_selections(std::move(list)), m_timestamp(timestamp) { sort_and_merge_overlapping(); @@ -509,7 +506,7 @@ SelectionList selection_list_from_string(Buffer& buffer, ConstArrayView auto sels = descs | transform([&](auto&& d) { auto s = selection_from_string(d); clamp(s, buffer); return s; }) | gather>(); - return {SelectionList::UnsortedTag{}, buffer, std::move(sels)}; + return {SelectionList::UnsortedTag{}, buffer, std::move(sels), buffer.timestamp(), 0}; } } diff --git a/src/selection.hh b/src/selection.hh index 33df78ce..1ab93aa5 100644 --- a/src/selection.hh +++ b/src/selection.hh @@ -88,8 +88,7 @@ struct SelectionList SelectionList(Buffer& buffer, Vector s, size_t timestamp); struct UnsortedTag {}; - SelectionList(UnsortedTag, Buffer& buffer, Vector s); - SelectionList(UnsortedTag, Buffer& buffer, Vector s, size_t timestamp); + SelectionList(UnsortedTag, Buffer& buffer, Vector s, size_t timestamp, size_t main); void update();