@@ -266,6 +266,7 @@ impl MappableCommand {
266266 change_selection_noyank, "Change selection (delete and enter insert mode, without yanking)",
267267 collapse_selection, "Collapse selection onto a single cursor",
268268 flip_selections, "Flip selection cursor and anchor",
269+ ensure_selections_forward, "Ensure the selection is in forward direction",
269270 insert_mode, "Insert before selection",
270271 append_mode, "Insert after selection (append)",
271272 command_mode, "Enter command mode",
@@ -1904,7 +1905,21 @@ fn flip_selections(cx: &mut Context) {
19041905 let selection = doc
19051906 .selection(view.id)
19061907 .clone()
1907− .transform(|range| Range::new(range.head, range.anchor));
1908+ .transform(|range| range.flip());
1909+ doc.set_selection(view.id, selection);
1910+}
1911+
1912+fn ensure_selections_forward(cx: &mut Context) {
1913+ let (view, doc) = current!(cx.editor);
1914+
1915+ let selection = doc
1916+ .selection(view.id)
1917+ .clone()
1918+ .transform(|r| match r.direction() {
1919+ Direction::Forward => r,
1920+ Direction::Backward => r.flip(),
1921+ });
1922+
19081923 doc.set_selection(view.id, selection);
19091924}
19101925