Move some only used once inline functions directly in their caller

No need to have that in a header, and not really selectors anyway
This commit is contained in:
Maxime Coste 2015-03-26 13:24:12 +00:00
parent 757366472b
commit 94bd32572d
2 changed files with 31 additions and 52 deletions

View File

@ -1355,27 +1355,53 @@ void select_whole_buffer(Context& context, NormalParams)
void keep_selection(Context& context, NormalParams p) void keep_selection(Context& context, NormalParams p)
{ {
keep_selection(context.selections(), p.count ? p.count-1 : context.selections().main_index()); auto& selections = context.selections();
const int index = p.count ? p.count-1 : selections.main_index();
if (index < selections.size())
selections = SelectionList{ selections.buffer(), std::move(selections[index]) };
selections.check_invariant();
} }
void remove_selection(Context& context, NormalParams p) void remove_selection(Context& context, NormalParams p)
{ {
remove_selection(context.selections(), p.count ? p.count-1 : context.selections().main_index()); auto& selections = context.selections();
const int index = p.count ? p.count-1 : selections.main_index();
if (selections.size() > 1 and index < selections.size())
{
selections.remove(index);
size_t main_index = selections.main_index();
if (index < main_index or main_index == selections.size())
selections.set_main_index(main_index - 1);
}
selections.check_invariant();
} }
void clear_selections(Context& context, NormalParams) void clear_selections(Context& context, NormalParams)
{ {
clear_selections(context.selections()); for (auto& sel : context.selections())
sel.anchor() = sel.cursor();
} }
void flip_selections(Context& context, NormalParams) void flip_selections(Context& context, NormalParams)
{ {
flip_selections(context.selections()); for (auto& sel : context.selections())
{
const ByteCoord tmp = sel.anchor();
sel.anchor() = sel.cursor();
sel.cursor() = tmp;
}
context.selections().check_invariant();
} }
void ensure_forward(Context& context, NormalParams) void ensure_forward(Context& context, NormalParams)
{ {
ensure_forward(context.selections()); for (auto& sel : context.selections())
{
const ByteCoord min = sel.min(), max = sel.max();
sel.anchor() = min;
sel.cursor() = max;
}
context.selections().check_invariant();
} }
static NormalCmdDesc cmds[] = static NormalCmdDesc cmds[] =

View File

@ -18,53 +18,6 @@ inline Selection keep_direction(Selection res, const Selection& ref)
return res; return res;
} }
inline void clear_selections(SelectionList& selections)
{
for (auto& sel : selections)
sel.anchor() = sel.cursor();
}
inline void flip_selections(SelectionList& selections)
{
for (auto& sel : selections)
{
const ByteCoord tmp = sel.anchor();
sel.anchor() = sel.cursor();
sel.cursor() = tmp;
}
selections.check_invariant();
}
inline void ensure_forward(SelectionList& selections)
{
for (auto& sel : selections)
{
const ByteCoord min = sel.min(), max = sel.max();
sel.anchor() = min;
sel.cursor() = max;
}
selections.check_invariant();
}
inline void keep_selection(SelectionList& selections, int index)
{
if (index < selections.size())
selections = SelectionList{ selections.buffer(), std::move(selections[index]) };
selections.check_invariant();
}
inline void remove_selection(SelectionList& selections, int index)
{
if (selections.size() > 1 and index < selections.size())
{
selections.remove(index);
size_t main_index = selections.main_index();
if (index < main_index or main_index == selections.size())
selections.set_main_index(main_index - 1);
}
selections.check_invariant();
}
using Utf8Iterator = utf8::iterator<BufferIterator, utf8::InvalidPolicy::Pass>; using Utf8Iterator = utf8::iterator<BufferIterator, utf8::InvalidPolicy::Pass>;
inline Selection utf8_range(const Utf8Iterator& first, const Utf8Iterator& last) inline Selection utf8_range(const Utf8Iterator& first, const Utf8Iterator& last)