diff options
| author | Maxime Coste <mawww@kakoune.org> | 2018-06-03 14:30:24 +1000 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2018-07-05 07:54:28 +1000 |
| commit | d6c6ed9bbf9185ad80f640078202c80cf1b2ae4e (patch) | |
| tree | 405dcc2b1d9130f27d063486b02042722abb99c9 /src/normal.cc | |
| parent | 8aba0b3cb4e5fe758328eba9eeba0401b4e77e52 (diff) | |
Store each selection as a separate element in a register
It makes more sense to use the list nature of the register to store
the selections instead of storing them as a single string separated
by spaces.
Diffstat (limited to 'src/normal.cc')
| -rw-r--r-- | src/normal.cc | 30 |
1 files changed, 13 insertions, 17 deletions
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<StringView>(' '); - 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 <buffer>@<timestamp>"} {} }; - const auto buffer_desc = *splitted.begin() | split<StringView>('@') | static_gather<error, 2>(); - Buffer& buffer = BufferManager::instance().get_buffer(buffer_desc[0]); - const size_t timestamp = str_to_int(buffer_desc[1]); + struct error : runtime_error { error(size_t) : runtime_error{"expected <buffer>@<timestamp>@main_index"} {} }; + const auto desc = content[0] | split<StringView>('@') | static_gather<error, 3>(); + 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]); - auto sels = splitted | skip(1) | transform(selection_from_string) | gather<Vector<Selection>>(); - if (sels.empty()) - throw runtime_error(format("register '{}' contains an empty selection list", reg)); + auto sels = content | skip(1) | transform(selection_from_string) | gather<Vector<Selection>>(); - 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<String>{format("{}@{}@{}", buffer.name(), buffer.timestamp(), sels.main_index())}, + sels | transform(selection_to_string)) | gather<Vector<String>>(); + RegisterManager::instance()[reg].set(context, descs); + context.print_status({format("{} {} selections to register '{}'", combine ? "Combined" : "Saved", sels.size(), reg), context.faces()["Information"]}); |
