@@ -247,6 +247,7 @@ impl MappableCommand {
247 extend_line, "Select current line, if already selected, extend to next line",
247 extend_line, "Select current line, if already selected, extend to next line",
248 extend_line_above, "Select current line, if already selected, extend to previous line",
248 extend_line_above, "Select current line, if already selected, extend to previous line",
249 extend_to_line_bounds, "Extend selection to line bounds (line-wise selection)",
249 extend_to_line_bounds, "Extend selection to line bounds (line-wise selection)",
250+ shrink_to_line_bounds, "Shrink selection to line bounds (line-wise selection)",
250 delete_selection, "Delete selection",
251 delete_selection, "Delete selection",
251 delete_selection_noyank, "Delete selection, without yanking",
252 delete_selection_noyank, "Delete selection, without yanking",
252 change_selection, "Change selection (delete and enter insert mode)",
253 change_selection, "Change selection (delete and enter insert mode)",
@@ -1942,6 +1943,47 @@ fn extend_to_line_bounds(cx: &mut Context) {
1946+fn shrink_to_line_bounds(cx: &mut Context) {
1947+ let (view, doc) = current!(cx.editor);
1951+ doc.selection(view.id).clone().transform(|range| {
1952+ let text = doc.text();
1954+ let (start_line, end_line) = range.line_range(text.slice(..));
1956+ // Do nothing if the selection is within one line to prevent
1957+ // conditional logic for the behavior of this command
1958+ if start_line == end_line {
1962+ let mut start = text.line_to_char(start_line);
1964+ // line_to_char gives us the start position of the line, so
1965+ // we need to get the start position of the next line. In
1966+ // the editor, this will correspond to the cursor being on
1967+ // the EOL whitespace charactor, which is what we want.
1968+ let mut end = text.line_to_char((end_line + 1).min(text.len_lines()));
1970+ if start != range.from() {
1971+ start = text.line_to_char((start_line + 1).min(text.len_lines()));
1974+ if end != range.to() {
1975+ end = text.line_to_char(end_line);
1978+ if range.anchor <= range.head {
1979+ Range::new(start, end)
1981+ Range::new(end, start)
1945enum Operation {
1987enum Operation {