@@ -2342,10 +2342,25 @@ enum Operation {
23422342 Change,
23432343}
23442344
2345+fn selection_is_linewise(selection: &Selection, text: &Rope) -> bool {
2346+ selection.ranges().iter().all(|range| {
2347+ let text = text.slice(..);
2348+ if range.slice(text).len_lines() < 2 {
2349+ return false;
2350+ }
2351+ // If the start of the selection is at the start of a line and the end at the end of a line.
2352+ let (start_line, end_line) = range.line_range(text);
2353+ let start = text.line_to_char(start_line);
2354+ let end = text.line_to_char((end_line + 1).min(text.len_lines()));
2355+ start == range.from() && end == range.to()
2356+ })
2357+}
2358+
23452359fn delete_selection_impl(cx: &mut Context, op: Operation) {
23462360 let (view, doc) = current!(cx.editor);
23472361
23482362 let selection = doc.selection(view.id);
2363+ let only_whole_lines = selection_is_linewise(selection, doc.text());
23492364
23502365 if cx.register != Some('_') {
23512366 // first yank the selection
@@ -2366,7 +2381,11 @@ fn delete_selection_impl(cx: &mut Context, op: Operation) {
23662381 exit_select_mode(cx);
23672382 }
23682383 Operation::Change => {
2369− enter_insert_mode(cx);
2384+ if only_whole_lines {
2385+ open_above(cx);
2386+ } else {
2387+ enter_insert_mode(cx);
2388+ }
23702389 }
23712390 }
23722391}