@@ -247,7 +247,8 @@ impl MappableCommand {
247 extend_search_prev, "Add previous search match to selection",
247 extend_search_prev, "Add previous search match to selection",
248 search_selection, "Use current selection as search pattern",
248 search_selection, "Use current selection as search pattern",
249 global_search, "Global search in workspace folder",
249 global_search, "Global search in workspace folder",
250− extend_line, "Select current line, if already selected, extend to next line",
250+ extend_line, "Select current line, if already selected, extend to another line based on the anchor",
251+ extend_line_below, "Select current line, if already selected, extend to next line",
251 extend_line_above, "Select current line, if already selected, extend to previous line",
252 extend_line_above, "Select current line, if already selected, extend to previous line",
252 extend_to_line_bounds, "Extend selection to line bounds",
253 extend_to_line_bounds, "Extend selection to line bounds",
253 shrink_to_line_bounds, "Shrink selection to line bounds",
254 shrink_to_line_bounds, "Shrink selection to line bounds",
@@ -1945,6 +1946,15 @@ enum Extend {
1947fn extend_line(cx: &mut Context) {
1948fn extend_line(cx: &mut Context) {
1949+ let (view, doc) = current_ref!(cx.editor);
1950+ let extend = match doc.selection(view.id).primary().direction() {
1951+ Direction::Forward => Extend::Below,
1952+ Direction::Backward => Extend::Above,
1954+ extend_line_impl(cx, extend);
1957+fn extend_line_below(cx: &mut Context) {
1948 extend_line_impl(cx, Extend::Below);
1958 extend_line_impl(cx, Extend::Below);
@@ -1960,20 +1970,32 @@ fn extend_line_impl(cx: &mut Context, extend: Extend) {
1960 let selection = doc.selection(view.id).clone().transform(|range| {
1970 let selection = doc.selection(view.id).clone().transform(|range| {
1961 let (start_line, end_line) = range.line_range(text.slice(..));
1971 let (start_line, end_line) = range.line_range(text.slice(..));
1963− let start = text.line_to_char(start_line);
1973+ let start = text.line_to_char(match extend {
1974+ Extend::Above => start_line.saturating_sub(count),
1975+ Extend::Below => start_line,
1964− let end = text.line_to_char((end_line + count).min(text.len_lines()));
1977+ let end = text.line_to_char(
1979+ Extend::Above => end_line + 1, // the start of next line
1980+ Extend::Below => (end_line + count),
1982+ .min(text.len_lines()),
1966 // extend to previous/next line if current line is selected
1985 // extend to previous/next line if current line is selected
1967 let (anchor, head) = if range.from() == start && range.to() == end {
1986 let (anchor, head) = if range.from() == start && range.to() == end {
1968 match extend {
1987 match extend {
1969− Extend::Above => (end, text.line_to_char(start_line.saturating_sub(1))),
1988+ Extend::Above => (end, text.line_to_char(start_line.saturating_sub(count + 1))),
1970 Extend::Below => (
1989 Extend::Below => (
1972 text.line_to_char((end_line + count + 1).min(text.len_lines())),
1991 text.line_to_char((end_line + count + 1).min(text.len_lines())),
1975 } else {
1994 } else {
1996+ Extend::Above => (end, start),
1976− (start, end)
1997+ Extend::Below => (start, end),
1979 Range::new(anchor, head)
2001 Range::new(anchor, head)