summaryrefslogtreecommitdiff
path: root/src/selectors.hh
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2014-09-18 00:34:23 +0100
committerMaxime Coste <frrrwww@gmail.com>2014-09-18 00:34:23 +0100
commitdd2bdea8ddc3b975bbd6ed967adcd9ecb7267380 (patch)
tree88f71a4525c5fb3ea912ed5dce342f98dd848512 /src/selectors.hh
parentbe85eb5d0b79391ce48340a2425dafa218027369 (diff)
Keep selection direction on split/select/search
Diffstat (limited to 'src/selectors.hh')
-rw-r--r--src/selectors.hh9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/selectors.hh b/src/selectors.hh
index 940ec222..6382b0da 100644
--- a/src/selectors.hh
+++ b/src/selectors.hh
@@ -9,6 +9,13 @@
namespace Kakoune
{
+inline Selection keep_direction(Selection res, const Selection& ref)
+{
+ if ((res.cursor() < res.anchor()) != (ref.cursor() < ref.anchor()))
+ std::swap<ByteCoord>(res.cursor(), res.anchor());
+ return res;
+}
+
inline void clear_selections(SelectionList& selections)
{
for (auto& sel : selections)
@@ -274,7 +281,7 @@ Selection find_next_match(const Buffer& buffer, const Selection& sel, const Rege
if (direction == Backward)
std::swap(begin, end);
- return {begin.coord(), end.coord(), std::move(captures)};
+ return keep_direction({begin.coord(), end.coord(), std::move(captures)}, sel);
}
void select_all_matches(SelectionList& selections,