@@ -1223,11 +1223,18 @@ fn search_impl(
1223 // skip empty matches that don't make sense
1223 // skip empty matches that don't make sense
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)
1232+ Range::new(start, end)
1226 let selection = match movement {
1235 let selection = match movement {
1227− Movement::Extend => selection.clone().push(Range::new(start, end)),
1236+ Movement::Extend => selection.clone().push(range),
1228− Movement::Move => selection
1230− .replace(selection.primary_index(), Range::new(start, end)),
1237+ Movement::Move => selection.clone().replace(selection.primary_index(), range),
1233 doc.set_selection(view.id, selection);
1240 doc.set_selection(view.id, selection);