Clamp selection generated in selection_list_from_string

Fixes #733
This commit is contained in:
Maxime Coste 2016-07-13 19:25:32 +01:00
parent bbceae97a2
commit 52d3b60aaa
4 changed files with 16 additions and 5 deletions

View File

@ -337,6 +337,12 @@ Vector<Selection> compute_modified_ranges(Buffer& buffer, size_t timestamp)
return ranges; 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<Selection>& selections, size_t& main, Buffer& buffer, size_t timestamp) void update_selections(Vector<Selection>& selections, size_t& main, Buffer& buffer, size_t timestamp)
{ {
if (timestamp == buffer.timestamp()) if (timestamp == buffer.timestamp())
@ -366,10 +372,8 @@ void update_selections(Vector<Selection>& selections, size_t& main, Buffer& buff
compare_selections)); compare_selections));
} }
for (auto& sel : selections) for (auto& sel : selections)
{ clamp(sel, buffer);
sel.anchor() = buffer.clamp(sel.anchor());
sel.cursor() = buffer.clamp(sel.cursor());
}
selections.erase(merge_overlapping(selections.begin(), selections.end(), selections.erase(merge_overlapping(selections.begin(), selections.end(),
main, overlaps), selections.end()); main, overlaps), selections.end());
} }
@ -604,7 +608,11 @@ SelectionList selection_list_from_string(Buffer& buffer, StringView desc)
Vector<Selection> sels; Vector<Selection> sels;
for (auto sel_desc : desc | split<StringView>(':')) for (auto sel_desc : desc | split<StringView>(':'))
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)}; return {buffer, std::move(sels)};
} }

View File

@ -0,0 +1 @@
:select 100.100,100.200<ret>

View File

@ -0,0 +1 @@
foo

View File

@ -0,0 +1 @@
foo