summaryrefslogtreecommitdiff
path: root/src/normal.cc
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2017-03-03 17:05:58 +0000
committerMaxime Coste <mawww@kakoune.org>2017-03-03 20:17:11 +0000
commit8a1e5d12ac16d083f9f3997735bac8d493e1a77b (patch)
tree3a69e2fef6efe83f07fa779b57164924add5ff2a /src/normal.cc
parente3cfde6d07cc8b52b46745609c18b3dc79883511 (diff)
Make <a-space> throw on invalid index or last selection
Diffstat (limited to 'src/normal.cc')
-rw-r--r--src/normal.cc17
1 files changed, 10 insertions, 7 deletions
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();
}