@@ -882,12 +882,11 @@ fn switch_to_lowercase(cx: &mut Context) {
882pub fn scroll(cx: &mut Context, offset: usize, direction: Direction) {
882pub fn scroll(cx: &mut Context, offset: usize, direction: Direction) {
883 use Direction::*;
883 use Direction::*;
884 let (view, doc) = current!(cx.editor);
884 let (view, doc) = current!(cx.editor);
885− let cursor = coords_at_pos(
885+
886− doc.text().slice(..),
887− doc.selection(view.id)
886+ let range = doc.selection(view.id).primary();
889− .cursor(doc.text().slice(..)),
887+ let text = doc.text().slice(..);
889+ let cursor = coords_at_pos(text, range.cursor(text));
891 let doc_last_line = doc.text().len_lines().saturating_sub(1);
890 let doc_last_line = doc.text().len_lines().saturating_sub(1);
893 let last_line = view.last_line(doc);
892 let last_line = view.last_line(doc);
@@ -917,11 +916,16 @@ pub fn scroll(cx: &mut Context, offset: usize, direction: Direction) {
917 .max(view.offset.row + scrolloff)
916 .max(view.offset.row + scrolloff)
918 .min(last_line.saturating_sub(scrolloff));
917 .min(last_line.saturating_sub(scrolloff));
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
921+ let anchor = if doc.mode == Mode::Select {
923 // TODO: only manipulate main selection
927 // TODO: only manipulate main selection
924− doc.set_selection(view.id, Selection::point(pos));
928+ doc.set_selection(view.id, Selection::single(anchor, head));
927fn page_up(cx: &mut Context) {
931fn page_up(cx: &mut Context) {