mirror of
https://github.com/mawww/kakoune.git
synced 2024-11-24 07:53:41 +03:00
Fix selection save/restore from registers post selection list syntax change
This commit is contained in:
parent
087a940fbe
commit
183f32803b
@ -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<StringView>(' ');
|
||||
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 <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]);
|
||||
|
||||
auto sels = StringView{desc.begin(), arobase} | split<StringView>(':')
|
||||
| transform(selection_from_string)
|
||||
| gather<Vector<Selection>>();
|
||||
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));
|
||||
|
||||
@ -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),
|
||||
|
1
test/normal/restore-selections/cmd
Normal file
1
test/normal/restore-selections/cmd
Normal file
@ -0,0 +1 @@
|
||||
Z<space>z
|
1
test/normal/restore-selections/in
Normal file
1
test/normal/restore-selections/in
Normal file
@ -0,0 +1 @@
|
||||
%(foo) %(bar) %(baz)
|
1
test/normal/restore-selections/selections
Normal file
1
test/normal/restore-selections/selections
Normal file
@ -0,0 +1 @@
|
||||
'foo' 'bar' 'baz'
|
Loading…
Reference in New Issue
Block a user