parent
b8cf457e82
commit
baae0c899b
|
@ -2250,13 +2250,18 @@ const CommandDesc select_cmd = {
|
|||
"select <selection_desc>...: select given selections\n"
|
||||
"\n"
|
||||
"selection_desc format is <anchor_line>.<anchor_column>,<cursor_line>.<cursor_column>",
|
||||
ParameterDesc{{}, ParameterDesc::Flags::SwitchesAsPositional, 1},
|
||||
ParameterDesc{
|
||||
{{"timestamp", {true, "specify buffer timestamp at which those selections are valid"}}},
|
||||
ParameterDesc::Flags::SwitchesOnlyAtStart, 1
|
||||
},
|
||||
CommandFlags::None,
|
||||
CommandHelper{},
|
||||
CommandCompleter{},
|
||||
[](const ParametersParser& parser, Context& context, const ShellContext&)
|
||||
{
|
||||
context.selections_write_only() = selection_list_from_string(context.buffer(), parser.positionals_from(0));
|
||||
auto& buffer = context.buffer();
|
||||
const size_t timestamp = parser.get_switch("timestamp").map(str_to_int_ifp).cast<size_t>().value_or(buffer.timestamp());
|
||||
context.selections_write_only() = selection_list_from_string(buffer, parser.positionals_from(0), timestamp);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -516,14 +516,14 @@ Selection selection_from_string(StringView desc)
|
|||
return Selection{anchor, cursor};
|
||||
}
|
||||
|
||||
SelectionList selection_list_from_string(Buffer& buffer, ConstArrayView<String> descs)
|
||||
SelectionList selection_list_from_string(Buffer& buffer, ConstArrayView<String> descs, size_t timestamp)
|
||||
{
|
||||
if (descs.empty())
|
||||
throw runtime_error{"empty selection description"};
|
||||
|
||||
auto sels = descs | transform([&](auto&& d) { auto s = selection_from_string(d); clamp(s, buffer); return s; })
|
||||
| gather<Vector<Selection>>();
|
||||
return {SelectionList::UnsortedTag{}, buffer, std::move(sels), buffer.timestamp(), 0};
|
||||
return {SelectionList::UnsortedTag{}, buffer, std::move(sels), timestamp, 0};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -163,7 +163,7 @@ Vector<Selection> compute_modified_ranges(Buffer& buffer, size_t timestamp);
|
|||
String selection_to_string(const Selection& selection);
|
||||
String selection_list_to_string(const SelectionList& selection);
|
||||
Selection selection_from_string(StringView desc);
|
||||
SelectionList selection_list_from_string(Buffer& buffer, ConstArrayView<String> descs);
|
||||
SelectionList selection_list_from_string(Buffer& buffer, ConstArrayView<String> descs, size_t timestamp);
|
||||
|
||||
}
|
||||
|
||||
|
|
1
test/compose/select-timestamp/cmd
Normal file
1
test/compose/select-timestamp/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
jxd:select -timestamp 1 3.1,3.2<ret>
|
4
test/compose/select-timestamp/in
Normal file
4
test/compose/select-timestamp/in
Normal file
|
@ -0,0 +1,4 @@
|
|||
aa
|
||||
bb
|
||||
cc
|
||||
dd
|
1
test/compose/select-timestamp/selections
Normal file
1
test/compose/select-timestamp/selections
Normal file
|
@ -0,0 +1 @@
|
|||
'cc'
|
Loading…
Reference in New Issue
Block a user