diff --git a/src/highlighters.cc b/src/highlighters.cc index fb8a45c8..dff32928 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -1212,10 +1212,6 @@ static void update_line_specs_ifn(const Buffer& buffer, LineAndSpecList& line_fl auto& lines = line_flags.list; - std::sort(lines.begin(), lines.end(), - [](const LineAndSpec& lhs, const LineAndSpec& rhs) - { return std::get<0>(lhs) < std::get<0>(rhs); }); - auto modifs = compute_line_modifications(buffer, line_flags.prefix); auto ins_pos = lines.begin(); for (auto it = lines.begin(); it != lines.end(); ++it) @@ -1246,6 +1242,13 @@ void option_update(LineAndSpecList& opt, const Context& context) update_line_specs_ifn(context.buffer(), opt); } +void option_list_postprocess(Vector& opt) +{ + std::sort(opt.begin(), opt.end(), + [](auto& lhs, auto& rhs) + { return std::get<0>(lhs) < std::get<0>(rhs); }); +} + struct FlagLinesHighlighter : Highlighter { FlagLinesHighlighter(String option_name, String default_face) @@ -1404,6 +1407,16 @@ static void update_ranges_ifn(const Buffer& buffer, RangeAndStringList& range_an range_and_faces.prefix = buffer.timestamp(); } +void option_list_postprocess(Vector& opt) +{ + std::sort(opt.begin(), opt.end(), + [](auto& lhs, auto& rhs) { + return std::get<0>(lhs).first == std::get<0>(rhs).first ? + std::get<0>(lhs).last < std::get<0>(rhs).last + : std::get<0>(lhs).first < std::get<0>(rhs).first; + }); +} + void option_update(RangeAndStringList& opt, const Context& context) { update_ranges_ifn(context.buffer(), opt); diff --git a/src/highlighters.hh b/src/highlighters.hh index cae0d63e..69979e32 100644 --- a/src/highlighters.hh +++ b/src/highlighters.hh @@ -27,6 +27,7 @@ constexpr StringView option_type_name(Meta::Type) return "line-specs"; } void option_update(LineAndSpecList& opt, const Context& context); +void option_list_postprocess(Vector& opt); using RangeAndString = std::tuple; using RangeAndStringList = TimestampedList; @@ -36,6 +37,7 @@ constexpr StringView option_type_name(Meta::Type) return "range-specs"; } void option_update(RangeAndStringList& opt, const Context& context); +void option_list_postprocess(Vector& opt); } diff --git a/src/option_types.hh b/src/option_types.hh index 0433d4d9..34e712ee 100644 --- a/src/option_types.hh +++ b/src/option_types.hh @@ -75,6 +75,10 @@ String option_to_string(const Vector& opt) list_separator); } +template +void option_list_postprocess(Vector& opt) +{} + template void option_from_string(StringView str, Vector& opt) { @@ -85,6 +89,7 @@ void option_from_string(StringView str, Vector& opt) option_from_string(elem, opt_elem); opt.push_back(opt_elem); } + option_list_postprocess(opt); } template @@ -95,6 +100,7 @@ bool option_add(Vector& opt, StringView str) opt.insert(opt.end(), std::make_move_iterator(vec.begin()), std::make_move_iterator(vec.end())); + option_list_postprocess(opt); return not vec.empty(); }