diff --git a/src/selection.cc b/src/selection.cc index 3cde21e4..36c1cdf2 100644 --- a/src/selection.cc +++ b/src/selection.cc @@ -337,6 +337,12 @@ Vector compute_modified_ranges(Buffer& buffer, size_t timestamp) return ranges; } +static void clamp(Selection& sel, const Buffer& buffer) +{ + sel.anchor() = buffer.clamp(sel.anchor()); + sel.cursor() = buffer.clamp(sel.cursor()); +} + void update_selections(Vector& selections, size_t& main, Buffer& buffer, size_t timestamp) { if (timestamp == buffer.timestamp()) @@ -366,10 +372,8 @@ void update_selections(Vector& selections, size_t& main, Buffer& buff compare_selections)); } for (auto& sel : selections) - { - sel.anchor() = buffer.clamp(sel.anchor()); - sel.cursor() = buffer.clamp(sel.cursor()); - } + clamp(sel, buffer); + selections.erase(merge_overlapping(selections.begin(), selections.end(), main, overlaps), selections.end()); } @@ -604,7 +608,11 @@ SelectionList selection_list_from_string(Buffer& buffer, StringView desc) Vector sels; for (auto sel_desc : desc | split(':')) - sels.push_back(selection_from_string(sel_desc)); + { + auto sel = selection_from_string(sel_desc); + clamp(sel, buffer); + sels.push_back(sel); + } return {buffer, std::move(sels)}; } diff --git a/test/regression/733-selection-list-from-string-not-valid/cmd b/test/regression/733-selection-list-from-string-not-valid/cmd new file mode 100644 index 00000000..d4d9f89c --- /dev/null +++ b/test/regression/733-selection-list-from-string-not-valid/cmd @@ -0,0 +1 @@ +:select 100.100,100.200 diff --git a/test/regression/733-selection-list-from-string-not-valid/in b/test/regression/733-selection-list-from-string-not-valid/in new file mode 100644 index 00000000..257cc564 --- /dev/null +++ b/test/regression/733-selection-list-from-string-not-valid/in @@ -0,0 +1 @@ +foo diff --git a/test/regression/733-selection-list-from-string-not-valid/out b/test/regression/733-selection-list-from-string-not-valid/out new file mode 100644 index 00000000..257cc564 --- /dev/null +++ b/test/regression/733-selection-list-from-string-not-valid/out @@ -0,0 +1 @@ +foo