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

SelectionList no longer inherit from std::vector

This commit is contained in:
Maxime Coste 2014-05-11 19:44:19 +01:00
parent 5e47c503d9
commit db8a4ca318
4 changed files with 47 additions and 14 deletions

View File

@ -13,7 +13,7 @@ public:
using iterator = SelectionList::iterator;
using const_iterator = SelectionList::const_iterator;
DynamicSelectionList(Buffer& buffer, SelectionList selections = {});
DynamicSelectionList(Buffer& buffer, SelectionList selections = { Selection{} });
DynamicSelectionList& operator=(SelectionList selections);
void check_invariant() const;

View File

@ -845,7 +845,7 @@ void indent(Context& context, int)
for (auto line = sel.min().line; line < sel.max().line+1; ++line)
{
if (indent_empty or buffer[line].length() > 1)
sels.emplace_back(line, line);
sels.push_back({line, line});
}
}
if (not sels.empty())
@ -881,12 +881,12 @@ void deindent(Context& context, int)
else
{
if (deindent_incomplete and width != 0)
sels.emplace_back(line, ByteCoord{line, column-1});
sels.push_back({ line, ByteCoord{line, column-1} });
break;
}
if (width == indent_width)
{
sels.emplace_back(line, ByteCoord{line, column});
sels.push_back({ line, ByteCoord{line, column} });
break;
}
}
@ -1245,7 +1245,7 @@ public:
auto it = std::upper_bound(m_ranges.begin(), m_ranges.end(), begin,
[](ByteCoord c, const Selection& sel)
{ return c < sel.min(); });
m_ranges.emplace(it, begin, buffer.char_prev(end));
m_ranges.insert(it, Selection{ begin, buffer.char_prev(end) });
}
void on_erase(const Buffer& buffer, ByteCoord begin, ByteCoord end)
@ -1255,7 +1255,7 @@ public:
auto it = std::upper_bound(m_ranges.begin(), m_ranges.end(), pos,
[](ByteCoord c, const Selection& sel)
{ return c < sel.min(); });
m_ranges.emplace(it, pos, pos);
m_ranges.insert(it, Selection{ pos, pos });
}
SelectionList& ranges() { return m_ranges; }

View File

@ -55,11 +55,11 @@ static bool compare_selections(const Selection& lhs, const Selection& rhs)
return lhs.min() < rhs.min();
}
struct SelectionList : std::vector<Selection>
struct SelectionList
{
SelectionList() = default;
SelectionList(ByteCoord c) : std::vector<Selection>{Selection{c,c}} {}
SelectionList(Selection s) : std::vector<Selection>{s} {}
SelectionList(ByteCoord c) : m_selections{Selection{c,c}} {}
SelectionList(Selection s) : m_selections{s} {}
void update_insert(const Buffer& buffer, ByteCoord begin, ByteCoord end);
void update_erase(const Buffer& buffer, ByteCoord begin, ByteCoord end);
@ -73,6 +73,38 @@ struct SelectionList : std::vector<Selection>
void rotate_main(int count) { m_main = (m_main + count) % size(); }
void push_back(const Selection& sel) { m_selections.push_back(sel); }
void push_back(Selection&& sel) { m_selections.push_back(std::move(sel)); }
Selection& operator[](size_t i) { return m_selections[i]; }
const Selection& operator[](size_t i) const { return m_selections[i]; }
using iterator = std::vector<Selection>::iterator;
iterator begin() { return m_selections.begin(); }
iterator end() { return m_selections.end(); }
using const_iterator = std::vector<Selection>::const_iterator;
const_iterator begin() const { return m_selections.begin(); }
const_iterator end() const { return m_selections.end(); }
template<typename... Args>
iterator insert(Args... args)
{
return m_selections.insert(std::forward<Args>(args)...);
}
template<typename... Args>
iterator erase(Args... args)
{
return m_selections.erase(std::forward<Args>(args)...);
}
size_t size() const { return m_selections.size(); }
bool empty() const { return m_selections.empty(); }
bool operator==(const SelectionList& other) const { return m_selections == other.m_selections; }
bool operator!=(const SelectionList& other) const { return m_selections != other.m_selections; }
template<typename OverlapsFunc>
void merge_overlapping(OverlapsFunc overlaps)
{
@ -117,6 +149,7 @@ struct SelectionList : std::vector<Selection>
private:
size_t m_main = 0;
std::vector<Selection> m_selections;
};
}

View File

@ -456,9 +456,9 @@ void select_all_matches(const Buffer& buffer, SelectionList& selections,
for (auto& match : *re_it)
captures.emplace_back(match.first, match.second);
result.emplace_back(begin.coord(),
(begin == end ? end : utf8::previous(end)).coord(),
std::move(captures));
result.push_back({ begin.coord(),
(begin == end ? end : utf8::previous(end)).coord(),
std::move(captures) });
}
}
if (result.empty())
@ -483,11 +483,11 @@ void split_selections(const Buffer& buffer, SelectionList& selections,
{
BufferIterator end = (*re_it)[0].first;
result.emplace_back(begin.coord(), (begin == end) ? end.coord() : utf8::previous(end).coord());
result.push_back({ begin.coord(), (begin == end) ? end.coord() : utf8::previous(end).coord() });
begin = (*re_it)[0].second;
}
if (begin.coord() <= sel.max())
result.emplace_back(begin.coord(), sel.max());
result.push_back({ begin.coord(), sel.max() });
}
result.set_main_index(result.size() - 1);
selections = std::move(result);