@@ -882,12 +882,11 @@ fn switch_to_lowercase(cx: &mut Context) {
882882pub fn scroll(cx: &mut Context, offset: usize, direction: Direction) {
883883 use Direction::*;
884884 let (view, doc) = current!(cx.editor);
885− let cursor = coords_at_pos(
886− doc.text().slice(..),
887− doc.selection(view.id)
888− .primary()
889− .cursor(doc.text().slice(..)),
890− );
885+
886+ let range = doc.selection(view.id).primary();
887+ let text = doc.text().slice(..);
888+
889+ let cursor = coords_at_pos(text, range.cursor(text));
891890 let doc_last_line = doc.text().len_lines().saturating_sub(1);
892891
893892 let last_line = view.last_line(doc);
@@ -917,11 +916,16 @@ pub fn scroll(cx: &mut Context, offset: usize, direction: Direction) {
917916 .max(view.offset.row + scrolloff)
918917 .min(last_line.saturating_sub(scrolloff));
919918
920− let text = doc.text().slice(..);
921− let pos = pos_at_coords(text, Position::new(line, cursor.col), true); // this func will properly truncate to line end
919+ let head = pos_at_coords(text, Position::new(line, cursor.col), true); // this func will properly truncate to line end
920+
921+ let anchor = if doc.mode == Mode::Select {
922+ range.anchor
923+ } else {
924+ head
925+ };
922926
923927 // TODO: only manipulate main selection
924− doc.set_selection(view.id, Selection::point(pos));
928+ doc.set_selection(view.id, Selection::single(anchor, head));
925929}
926930
927931fn page_up(cx: &mut Context) {