diff options
| author | Maxime Coste <mawww@kakoune.org> | 2018-06-03 21:08:45 +1000 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2018-07-05 07:54:28 +1000 |
| commit | 124a5d49059c1eb8ade653ef35ca9595041fc249 (patch) | |
| tree | 941010800dd29aed6a3af4a3e642ef6e56ea4b93 /src/selection.cc | |
| parent | ed123a2cc90c56b18669ea99ff5da49f3650eaae (diff) | |
Tolerate restoring invalid coordinates from register
Clamp those selection after updating them to the current timestamp
Fixes #2078
Diffstat (limited to 'src/selection.cc')
| -rw-r--r-- | src/selection.cc | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/src/selection.cc b/src/selection.cc index 02358fea..c8ab543b 100644 --- a/src/selection.cc +++ b/src/selection.cc @@ -212,6 +212,12 @@ static void clamp(Selection& sel, const Buffer& buffer) sel.cursor() = buffer.clamp(sel.cursor()); } +void clamp_selections(Vector<Selection>& selections, const Buffer& buffer) +{ + for (auto& sel : selections) + clamp(sel, buffer); +} + void update_selections(Vector<Selection>& selections, size_t& main, Buffer& buffer, size_t timestamp) { if (timestamp == buffer.timestamp()) @@ -286,30 +292,41 @@ void SelectionList::check_invariant() const #endif } -void SelectionList::sort() +void sort_selections(Vector<Selection>& selections, size_t& main_index) { - if (size() == 1) + if (selections.size() == 1) return; - const auto& main = this->main(); + const auto& main = selections[main_index]; const auto main_begin = main.min(); - m_main = std::count_if(begin(), end(), [&](const Selection& sel) { - auto begin = sel.min(); - if (begin == main_begin) - return &sel < &main; - else - return begin < main_begin; - }); - std::stable_sort(begin(), end(), compare_selections); + main_index = std::count_if(selections.begin(), selections.end(), + [&](const Selection& sel) { + auto begin = sel.min(); + if (begin == main_begin) + return &sel < &main; + else + return begin < main_begin; + }); + std::stable_sort(selections.begin(), selections.end(), compare_selections); } -void SelectionList::merge_overlapping() +void merge_overlapping_selections(Vector<Selection>& selections, size_t& main_index) { - if (size() == 1) + if (selections.size() == 1) return; - m_selections.erase(Kakoune::merge_overlapping(begin(), end(), - m_main, overlaps), end()); + selections.erase(Kakoune::merge_overlapping(selections.begin(), selections.end(), + main_index, overlaps), selections.end()); +} + +void SelectionList::sort() +{ + sort_selections(m_selections, m_main); +} + +void SelectionList::merge_overlapping() +{ + merge_overlapping_selections(m_selections, m_main); } void SelectionList::merge_consecutive() |
