diff options
| author | Maxime Coste <mawww@kakoune.org> | 2019-04-01 22:10:41 +1100 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2019-04-01 22:11:18 +1100 |
| commit | baae0c899b14439487b661fa593c80f792855be3 (patch) | |
| tree | ff7528820df4f18bad9788cd83cb02a009c879f7 /src | |
| parent | b8cf457e82a18233b30c696577ea57dd85aee6b8 (diff) | |
Add -timestamp switch support to the select command
Fixes #2829
Diffstat (limited to 'src')
| -rw-r--r-- | src/commands.cc | 9 | ||||
| -rw-r--r-- | src/selection.cc | 4 | ||||
| -rw-r--r-- | src/selection.hh | 2 |
3 files changed, 10 insertions, 5 deletions
diff --git a/src/commands.cc b/src/commands.cc index 31470f8f..4176f673 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -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); } }; diff --git a/src/selection.cc b/src/selection.cc index 3fff6eb8..30ff599b 100644 --- a/src/selection.cc +++ b/src/selection.cc @@ -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}; } } diff --git a/src/selection.hh b/src/selection.hh index bd7e35c2..f83d4e4b 100644 --- a/src/selection.hh +++ b/src/selection.hh @@ -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); } |
