Merge remote-tracking branch 'occivink/master'

This commit is contained in:
Maxime Coste 2017-03-03 21:13:16 +00:00
commit f8a625bc2f

View File

@ -1717,8 +1717,10 @@ void keep_selection(Context& context, NormalParams p)
{ {
auto& selections = context.selections(); auto& selections = context.selections();
const int index = p.count ? p.count-1 : selections.main_index(); const int index = p.count ? p.count-1 : selections.main_index();
if (index < selections.size()) if (index >= selections.size())
selections = SelectionList{ selections.buffer(), std::move(selections[index]) }; throw runtime_error{format("invalid selection index: {}", index)};
selections = SelectionList{ selections.buffer(), std::move(selections[index]) };
selections.check_invariant(); selections.check_invariant();
} }
@ -1726,9 +1728,8 @@ void remove_selection(Context& context, NormalParams p)
{ {
auto& selections = context.selections(); auto& selections = context.selections();
const int index = p.count ? p.count-1 : selections.main_index(); const int index = p.count ? p.count-1 : selections.main_index();
if (index >= selections.size()) if (index >= selections.size())
throw runtime_error{format("There is not {}th selection", index)}; throw runtime_error{format("invalid selection index: {}", index)};
if (selections.size() == 1) if (selections.size() == 1)
throw runtime_error{"Cannot remove the last selection"}; throw runtime_error{"Cannot remove the last selection"};