Make <a-space> throw on invalid index or last selection
This commit is contained in:
parent
e3cfde6d07
commit
8a1e5d12ac
|
@ -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())
|
||||
{
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user