@@ -247,6 +247,7 @@ impl MappableCommand {
247247 search_selection, "Use current selection as search pattern",
248248 global_search, "Global Search in workspace folder",
249249 extend_line, "Select current line, if already selected, extend to next line",
250+ extend_line_above, "Select current line, if already selected, extend to previous line",
250251 extend_to_line_bounds, "Extend selection to line bounds (line-wise selection)",
251252 delete_selection, "Delete selection",
252253 delete_selection_noyank, "Delete selection, without yanking",
@@ -1854,7 +1855,20 @@ fn global_search(cx: &mut Context) {
18541855 cx.jobs.callback(show_picker);
18551856}
18561857
1858+enum Extend {
1859+ Above,
1860+ Below,
1861+}
1862+
18571863fn extend_line(cx: &mut Context) {
1864+ extend_line_impl(cx, Extend::Below);
1865+}
1866+
1867+fn extend_line_above(cx: &mut Context) {
1868+ extend_line_impl(cx, Extend::Above);
1869+}
1870+
1871+fn extend_line_impl(cx: &mut Context, extend: Extend) {
18581872 let count = cx.count();
18591873 let (view, doc) = current!(cx.editor);
18601874
@@ -1863,13 +1877,22 @@ fn extend_line(cx: &mut Context) {
18631877 let (start_line, end_line) = range.line_range(text.slice(..));
18641878
18651879 let start = text.line_to_char(start_line);
1866− let mut end = text.line_to_char((end_line + count).min(text.len_lines()));
1880+ let end = text.line_to_char((end_line + count).min(text.len_lines()));
1881+
1882+ // extend to previous/next line if current line is selected
1883+ let (anchor, head) = if range.from() == start && range.to() == end {
1884+ match extend {
1885+ Extend::Above => (end, text.line_to_char(start_line.saturating_sub(1))),
1886+ Extend::Below => (
1887+ start,
1888+ text.line_to_char((end_line + count + 1).min(text.len_lines())),
1889+ ),
1890+ }
1891+ } else {
1892+ (start, end)
1893+ };
18671894
1868− // go to next line if current line is selected
1869− if range.from() == start && range.to() == end {
1870− end = text.line_to_char((end_line + count + 1).min(text.len_lines()));
1871− }
1872− Range::new(start, end)
1895+ Range::new(anchor, head)
18731896 });
18741897
18751898 doc.set_selection(view.id, selection);