1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-11-28 01:00:28 +03:00

Fix selection save/restore from registers post selection list syntax change

This commit is contained in:
Maxime Coste 2018-06-03 14:10:07 +10:00
parent 087a940fbe
commit 183f32803b
4 changed files with 13 additions and 13 deletions

View File

@ -1730,19 +1730,16 @@ SelectionList read_selections_from_register(char reg, Context& context)
if (content.size() != 1) if (content.size() != 1)
throw runtime_error(format("register '{}' does not contain a selections desc", reg)); throw runtime_error(format("register '{}' does not contain a selections desc", reg));
StringView desc = content[0]; auto splitted = content[0] | split<StringView>(' ');
auto arobase = find(desc, '@'); if (splitted.begin() == splitted.end())
auto percent = find(desc, '%');
if (arobase == desc.end() or percent == desc.end())
throw runtime_error(format("register '{}' does not contain a selections desc", reg)); throw runtime_error(format("register '{}' does not contain a selections desc", reg));
Buffer& buffer = BufferManager::instance().get_buffer({arobase+1, percent}); struct error : runtime_error { error(size_t) : runtime_error{"expected <buffer>@<timestamp>"} {} };
size_t timestamp = str_to_int({percent + 1, desc.end()}); 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]);
auto sels = StringView{desc.begin(), arobase} | split<StringView>(':') auto sels = splitted | skip(1) | transform(selection_from_string) | gather<Vector<Selection>>();
| transform(selection_from_string)
| gather<Vector<Selection>>();
if (sels.empty()) if (sels.empty())
throw runtime_error(format("register '{}' contains an empty selection list", reg)); 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(); const bool empty = content.size() == 1 and content[0].empty();
auto save_to_reg = [reg](Context& context, const SelectionList& sels) { auto save_to_reg = [reg](Context& context, const SelectionList& sels) {
String desc = format("{}@{}%{}", selection_list_to_string(sels), String desc = format("{}@{} {}", context.buffer().name(),
context.buffer().name(), context.buffer().timestamp(),
context.buffer().timestamp()); selection_list_to_string(sels));
RegisterManager::instance()[reg].set(context, desc); RegisterManager::instance()[reg].set(context, desc);
context.print_status({format("{} {} selections to register '{}'", context.print_status({format("{} {} selections to register '{}'",
combine ? "Combined" : "Saved", sels.size(), reg), combine ? "Combined" : "Saved", sels.size(), reg),

View File

@ -0,0 +1 @@
Z<space>z

View File

@ -0,0 +1 @@
%(foo) %(bar) %(baz)

View File

@ -0,0 +1 @@
'foo' 'bar' 'baz'