diff --git a/src/normal.cc b/src/normal.cc index c8ff9c78..62cfb864 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -1163,7 +1163,7 @@ static boost::optional compute_modified_ranges(Buffer& buffer, si const ByteCoord& end = change.end; if (change.type == Buffer::Change::Insert) { - update_insert(ranges, begin, end, change.at_end); + update_insert(ranges, begin, end); auto it = std::upper_bound(ranges.begin(), ranges.end(), begin, [](ByteCoord c, const Selection& sel) { return c < sel.min(); }); @@ -1171,7 +1171,7 @@ static boost::optional compute_modified_ranges(Buffer& buffer, si } else { - update_erase(ranges, begin, end, change.at_end); + update_erase(ranges, begin, end); auto pos = begin; if (change.at_end) pos = begin.column ? ByteCoord{begin.line, begin.column - 1} @@ -1185,6 +1185,12 @@ static boost::optional compute_modified_ranges(Buffer& buffer, si if (ranges.empty()) return {}; + for (auto& sel : ranges) + { + sel.anchor() = buffer.clamp(sel.anchor()); + sel.cursor() = buffer.clamp(sel.cursor()); + } + SelectionList result{buffer, std::move(ranges)}; auto touches = [&](const Selection& lhs, const Selection& rhs) { diff --git a/src/selection.cc b/src/selection.cc index c37829c2..d3c798b0 100644 --- a/src/selection.cc +++ b/src/selection.cc @@ -1,7 +1,6 @@ #include "selection.hh" #include "utf8.hh" -#include "modification.hh" #include "buffer_utils.hh" namespace Kakoune @@ -16,93 +15,6 @@ void Selection::merge_with(const Selection& range) m_anchor = std::max(m_anchor, range.m_anchor); } -namespace -{ - -template