@@ -247,6 +247,7 @@ impl MappableCommand {
247247 extend_line, "Select current line, if already selected, extend to next line",
248248 extend_line_above, "Select current line, if already selected, extend to previous line",
249249 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)",
250251 delete_selection, "Delete selection",
251252 delete_selection_noyank, "Delete selection, without yanking",
252253 change_selection, "Change selection (delete and enter insert mode)",
@@ -1942,6 +1943,47 @@ fn extend_to_line_bounds(cx: &mut Context) {
19421943 );
19431944}
19441945
1946+fn shrink_to_line_bounds(cx: &mut Context) {
1947+ let (view, doc) = current!(cx.editor);
1948+
1949+ doc.set_selection(
1950+ view.id,
1951+ doc.selection(view.id).clone().transform(|range| {
1952+ let text = doc.text();
1953+
1954+ let (start_line, end_line) = range.line_range(text.slice(..));
1955+
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 {
1959+ return range;
1960+ }
1961+
1962+ let mut start = text.line_to_char(start_line);
1963+
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()));
1969+
1970+ if start != range.from() {
1971+ start = text.line_to_char((start_line + 1).min(text.len_lines()));
1972+ }
1973+
1974+ if end != range.to() {
1975+ end = text.line_to_char(end_line);
1976+ }
1977+
1978+ if range.anchor <= range.head {
1979+ Range::new(start, end)
1980+ } else {
1981+ Range::new(end, start)
1982+ }
1983+ }),
1984+ );
1985+}
1986+
19451987enum Operation {
19461988 Delete,
19471989 Change,