@@ -1223,11 +1223,18 @@ fn search_impl(
12231223 // skip empty matches that don't make sense
12241224 return;
12251225 }
1226+
1227+ // Determine range direction based on the primary range
1228+ let primary = selection.primary();
1229+ let range = if primary.head < primary.anchor {
1230+ Range::new(end, start)
1231+ } else {
1232+ Range::new(start, end)
1233+ };
1234+
12261235 let selection = match movement {
1227− Movement::Extend => selection.clone().push(Range::new(start, end)),
1228− Movement::Move => selection
1229− .clone()
1230− .replace(selection.primary_index(), Range::new(start, end)),
1236+ Movement::Extend => selection.clone().push(range),
1237+ Movement::Move => selection.clone().replace(selection.primary_index(), range),
12311238 };
12321239
12331240 doc.set_selection(view.id, selection);