1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-11-28 09:07:19 +03:00

Ensure line-specs and range-specs options are sorted internally

This commit is contained in:
Maxime Coste 2017-11-02 09:51:15 +08:00
parent 424b2389cb
commit 53069bcb2d
3 changed files with 25 additions and 4 deletions

View File

@ -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<LineAndSpec, MemoryDomain::Options>& 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<RangeAndString, MemoryDomain::Options>& 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);

View File

@ -27,6 +27,7 @@ constexpr StringView option_type_name(Meta::Type<LineAndSpecList>)
return "line-specs";
}
void option_update(LineAndSpecList& opt, const Context& context);
void option_list_postprocess(Vector<LineAndSpec, MemoryDomain::Options>& opt);
using RangeAndString = std::tuple<InclusiveBufferRange, String>;
using RangeAndStringList = TimestampedList<RangeAndString>;
@ -36,6 +37,7 @@ constexpr StringView option_type_name(Meta::Type<RangeAndStringList>)
return "range-specs";
}
void option_update(RangeAndStringList& opt, const Context& context);
void option_list_postprocess(Vector<RangeAndString, MemoryDomain::Options>& opt);
}

View File

@ -75,6 +75,10 @@ String option_to_string(const Vector<T, domain>& opt)
list_separator);
}
template<typename T, MemoryDomain domain>
void option_list_postprocess(Vector<T, domain>& opt)
{}
template<typename T, MemoryDomain domain>
void option_from_string(StringView str, Vector<T, domain>& opt)
{
@ -85,6 +89,7 @@ void option_from_string(StringView str, Vector<T, domain>& opt)
option_from_string(elem, opt_elem);
opt.push_back(opt_elem);
}
option_list_postprocess(opt);
}
template<typename T, MemoryDomain domain>
@ -95,6 +100,7 @@ bool option_add(Vector<T, domain>& 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();
}