Move SelectMode enum as an implementation detail in normal.cc

This commit is contained in:
Maxime Coste 2013-12-15 14:38:04 +00:00
parent 39b43f4c3c
commit eb81eef03e
3 changed files with 32 additions and 32 deletions

View File

@ -12,14 +12,6 @@ namespace InputModes { class Insert; }
class Register;
enum class SelectMode
{
Replace,
Extend,
Append,
ReplaceMain,
};
enum class InsertMode : unsigned
{
Insert,

View File

@ -22,6 +22,14 @@ namespace Kakoune
using namespace std::placeholders;
enum class SelectMode
{
Replace,
Extend,
Append,
ReplaceMain,
};
template<SelectMode mode, typename T>
class Select
{
@ -360,6 +368,30 @@ void pipe(Context& context, int)
});
}
template<Direction direction, SelectMode mode>
void select_next_match(const Buffer& buffer, SelectionList& selections,
const Regex& regex)
{
if (mode == SelectMode::Replace)
{
for (auto& sel : selections)
sel = find_next_match<direction>(buffer, sel, regex);
}
if (mode == SelectMode::Extend)
{
for (auto& sel : selections)
sel.merge_with(find_next_match<direction>(buffer, sel, regex));
}
else if (mode == SelectMode::ReplaceMain)
selections.main() = find_next_match<direction>(buffer, selections.main(), regex);
else if (mode == SelectMode::Append)
{
selections.push_back(find_next_match<direction>(buffer, selections.main(), regex));
selections.set_main_index(selections.size() - 1);
}
selections.sort_and_merge_overlapping();
}
template<SelectMode mode, Direction direction>
void search(Context& context, int)
{

View File

@ -266,30 +266,6 @@ Selection find_next_match(const Buffer& buffer, const Selection& sel, const Rege
return {begin.coord(), end.coord(), std::move(captures)};
}
template<Direction direction, SelectMode mode>
void select_next_match(const Buffer& buffer, SelectionList& selections,
const Regex& regex)
{
if (mode == SelectMode::Replace)
{
for (auto& sel : selections)
sel = find_next_match<direction>(buffer, sel, regex);
}
if (mode == SelectMode::Extend)
{
for (auto& sel : selections)
sel.merge_with(find_next_match<direction>(buffer, sel, regex));
}
else if (mode == SelectMode::ReplaceMain)
selections.main() = find_next_match<direction>(buffer, selections.main(), regex);
else if (mode == SelectMode::Append)
{
selections.push_back(find_next_match<direction>(buffer, selections.main(), regex));
selections.set_main_index(selections.size() - 1);
}
selections.sort_and_merge_overlapping();
}
void select_all_matches(const Buffer& buffer, SelectionList& selections,
const Regex& regex);