diff --git a/src/normal.cc b/src/normal.cc index 9eabc20c..ae59d9fc 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -1710,13 +1710,16 @@ void remove_selection(Context& context, NormalParams p) { 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); - } + + if (index >= selections.size()) + throw runtime_error{format("There is not {}th selection", index)}; + if (selections.size() == 1) + throw runtime_error{"Cannot remove the last selection"}; + + 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(); }