From baae0c899b14439487b661fa593c80f792855be3 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 1 Apr 2019 22:10:41 +1100 Subject: [PATCH] Add -timestamp switch support to the select command Fixes #2829 --- src/commands.cc | 9 +++++++-- src/selection.cc | 4 ++-- src/selection.hh | 2 +- test/compose/select-timestamp/cmd | 1 + test/compose/select-timestamp/in | 4 ++++ test/compose/select-timestamp/selections | 1 + 6 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 test/compose/select-timestamp/cmd create mode 100644 test/compose/select-timestamp/in create mode 100644 test/compose/select-timestamp/selections 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 ...: select given selections\n" "\n" "selection_desc format is .,.", - 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().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 descs) +SelectionList selection_list_from_string(Buffer& buffer, ConstArrayView 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>(); - 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 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 descs); +SelectionList selection_list_from_string(Buffer& buffer, ConstArrayView descs, size_t timestamp); } diff --git a/test/compose/select-timestamp/cmd b/test/compose/select-timestamp/cmd new file mode 100644 index 00000000..c071dd90 --- /dev/null +++ b/test/compose/select-timestamp/cmd @@ -0,0 +1 @@ +jxd:select -timestamp 1 3.1,3.2 diff --git a/test/compose/select-timestamp/in b/test/compose/select-timestamp/in new file mode 100644 index 00000000..955bebf3 --- /dev/null +++ b/test/compose/select-timestamp/in @@ -0,0 +1,4 @@ +aa +bb +cc +dd diff --git a/test/compose/select-timestamp/selections b/test/compose/select-timestamp/selections new file mode 100644 index 00000000..51ae1622 --- /dev/null +++ b/test/compose/select-timestamp/selections @@ -0,0 +1 @@ +'cc'