aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-11-06 08:41:30 +0000
committerBlaž Hrastnik2021-11-06 08:41:30 +0000
commitb81a5544248633d84615952ec6130f5104998c18 (patch)
treea47a0c9002658da728545b98b5a01c1e9064578d
parent6431b26a6a5fa4be5b91008f21537721d2ff4ba2 (diff)
Retain range direction on search
Co-authored-by: CossonLeo <20379044+cossonleo@users.noreply.github.com>
-rw-r--r--helix-term/src/commands.rs15
1 files changed, 11 insertions, 4 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index e3ebd128..752b5900 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -1223,11 +1223,18 @@ fn search_impl(
// skip empty matches that don't make sense
return;
}
+
+ // Determine range direction based on the primary range
+ let primary = selection.primary();
+ let range = if primary.head < primary.anchor {
+ Range::new(end, start)
+ } else {
+ Range::new(start, end)
+ };
+
let selection = match movement {
- Movement::Extend => selection.clone().push(Range::new(start, end)),
- Movement::Move => selection
- .clone()
- .replace(selection.primary_index(), Range::new(start, end)),
+ Movement::Extend => selection.clone().push(range),
+ Movement::Move => selection.clone().replace(selection.primary_index(), range),
};
doc.set_selection(view.id, selection);