@@ -266,6 +266,7 @@ impl MappableCommand {
266 change_selection_noyank, "Change selection (delete and enter insert mode, without yanking)",
266 change_selection_noyank, "Change selection (delete and enter insert mode, without yanking)",
267 collapse_selection, "Collapse selection onto a single cursor",
267 collapse_selection, "Collapse selection onto a single cursor",
268 flip_selections, "Flip selection cursor and anchor",
268 flip_selections, "Flip selection cursor and anchor",
269+ ensure_selections_forward, "Ensure the selection is in forward direction",
269 insert_mode, "Insert before selection",
270 insert_mode, "Insert before selection",
270 append_mode, "Insert after selection (append)",
271 append_mode, "Insert after selection (append)",
271 command_mode, "Enter command mode",
272 command_mode, "Enter command mode",
@@ -1904,7 +1905,21 @@ fn flip_selections(cx: &mut Context) {
1904 let selection = doc
1905 let selection = doc
1905 .selection(view.id)
1906 .selection(view.id)
1906 .clone()
1907 .clone()
1907− .transform(|range| Range::new(range.head, range.anchor));
1908+ .transform(|range| range.flip());
1909+ doc.set_selection(view.id, selection);
1912+fn ensure_selections_forward(cx: &mut Context) {
1913+ let (view, doc) = current!(cx.editor);
1915+ let selection = doc
1916+ .selection(view.id)
1918+ .transform(|r| match r.direction() {
1919+ Direction::Forward => r,
1920+ Direction::Backward => r.flip(),
1908 doc.set_selection(view.id, selection);
1923 doc.set_selection(view.id, selection);