summaryrefslogtreecommitdiff
path: root/src/normal.cc
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2018-06-03 21:08:45 +1000
committerMaxime Coste <mawww@kakoune.org>2018-07-05 07:54:28 +1000
commit124a5d49059c1eb8ade653ef35ca9595041fc249 (patch)
tree941010800dd29aed6a3af4a3e642ef6e56ea4b93 /src/normal.cc
parented123a2cc90c56b18669ea99ff5da49f3650eaae (diff)
Tolerate restoring invalid coordinates from register
Clamp those selection after updating them to the current timestamp Fixes #2078
Diffstat (limited to 'src/normal.cc')
-rw-r--r--src/normal.cc19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/normal.cc b/src/normal.cc
index e66045a3..fb295f4d 100644
--- a/src/normal.cc
+++ b/src/normal.cc
@@ -1734,11 +1734,22 @@ SelectionList read_selections_from_register(char reg, Context& context)
const auto desc = content[0] | split<StringView>('@') | static_gather<error, 3>();
Buffer& buffer = BufferManager::instance().get_buffer(desc[0]);
const size_t timestamp = str_to_int(desc[1]);
- const size_t main = str_to_int(desc[2]);
+ size_t main = str_to_int(desc[2]);
+
+ if (timestamp > buffer.timestamp())
+ throw runtime_error{"register '{}' refers to an invalid timestamp"};
auto sels = content | skip(1) | transform(selection_from_string) | gather<Vector<Selection>>();
+ sort_selections(sels, main);
+ merge_overlapping_selections(sels, main);
+ if (timestamp < buffer.timestamp())
+ update_selections(sels, main, buffer, timestamp);
+ else
+ clamp_selections(sels, buffer);
- return {SelectionList::UnsortedTag{}, buffer, std::move(sels), timestamp, main};
+ SelectionList res{buffer, std::move(sels)};
+ res.set_main_index(main);
+ return res;
}
enum class CombineOp
@@ -2012,9 +2023,7 @@ void move_cursor(Context& context, NormalParams params)
sel.anchor() = mode == SelectMode::Extend ? sel.anchor() : cursor;
sel.cursor() = cursor;
}
- selections.sort();
-
- selections.merge_overlapping();
+ selections.sort_and_merge_overlapping();
}
void select_whole_buffer(Context& context, NormalParams)