Skip to content

Commit

Permalink
scroll: change only main selection, only when needed (#1420)
Browse files Browse the repository at this point in the history
Co-authored-by: mathis <mathis.brossier@universite-paris-saclay.fr>
  • Loading branch information
k2d222 and mathis authored Jan 3, 2022
1 parent 609f736 commit dbaed0b
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1282,16 +1282,23 @@ pub fn scroll(cx: &mut Context, offset: usize, direction: Direction) {
.max(view.offset.row + scrolloff)
.min(last_line.saturating_sub(scrolloff));

let head = pos_at_coords(text, Position::new(line, cursor.col), true); // this func will properly truncate to line end
// If cursor needs moving, replace primary selection
if line != cursor.row {
let head = pos_at_coords(text, Position::new(line, cursor.col), true); // this func will properly truncate to line end

let anchor = if doc.mode == Mode::Select {
range.anchor
} else {
head
};
let anchor = if doc.mode == Mode::Select {
range.anchor
} else {
head
};

// TODO: only manipulate main selection
doc.set_selection(view.id, Selection::single(anchor, head));
// replace primary selection with an empty selection at cursor pos
let prim_sel = Range::new(anchor, head);
let mut sel = doc.selection(view.id).clone();
let idx = sel.primary_index();
sel = sel.replace(idx, prim_sel);
doc.set_selection(view.id, sel);
}
}

fn page_up(cx: &mut Context) {
Expand Down

0 comments on commit dbaed0b

Please sign in to comment.