@@ -1282,16 +1282,23 @@ pub fn scroll(cx: &mut Context, offset: usize, direction: Direction) {
12821282 .max(view.offset.row + scrolloff)
12831283 .min(last_line.saturating_sub(scrolloff));
12841284
1285− let head = pos_at_coords(text, Position::new(line, cursor.col), true); // this func will properly truncate to line end
1285+ // If cursor needs moving, replace primary selection
1286+ if line != cursor.row {
1287+ let head = pos_at_coords(text, Position::new(line, cursor.col), true); // this func will properly truncate to line end
12861288
1287− let anchor = if doc.mode == Mode::Select {
1288− range.anchor
1289− } else {
1290− head
1291− };
1289+ let anchor = if doc.mode == Mode::Select {
1290+ range.anchor
1291+ } else {
1292+ head
1293+ };
12921294
1293− // TODO: only manipulate main selection
1294− doc.set_selection(view.id, Selection::single(anchor, head));
1295+ // replace primary selection with an empty selection at cursor pos
1296+ let prim_sel = Range::new(anchor, head);
1297+ let mut sel = doc.selection(view.id).clone();
1298+ let idx = sel.primary_index();
1299+ sel = sel.replace(idx, prim_sel);
1300+ doc.set_selection(view.id, sel);
1301+ }
12951302}
12961303
12971304fn page_up(cx: &mut Context) {