Skip to content

Commit

Permalink
mouse operations respect scrolloff
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterliao29 committed Dec 22, 2022
1 parent c4263d6 commit 475ce49
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,7 @@ impl EditorView {
}

editor.focus(view_id);
editor.ensure_cursor_in_view(view_id);

return EventResult::Consumed(None);
}
Expand All @@ -1180,19 +1181,21 @@ impl EditorView {
}

MouseEventKind::Drag(MouseButton::Left) => {
let (view, doc) = current!(cxt.editor);
let editor = &mut cxt.editor;

let pos = match view.pos_at_screen_coords(doc, row, column) {
Some(pos) => pos,
None => return EventResult::Ignored(None),
};
if let Some((pos, view_id)) = pos_and_view(editor, row, column) {
let doc = doc_mut!(editor, &view!(editor, view_id).doc);

let mut selection = doc.selection(view.id).clone();
let primary = selection.primary_mut();
*primary = primary.put_cursor(doc.text().slice(..), pos, true);
doc.set_selection(view.id, selection);
let mut selection = doc.selection(view_id).clone();
let primary = selection.primary_mut();
*primary = primary.put_cursor(doc.text().slice(..), pos, true);
doc.set_selection(view_id, selection);

EventResult::Consumed(None)
editor.ensure_cursor_in_view(view_id);

return EventResult::Consumed(None);
}
EventResult::Ignored(None)
}

MouseEventKind::ScrollUp | MouseEventKind::ScrollDown => {
Expand All @@ -1213,6 +1216,7 @@ impl EditorView {
commands::scroll(cxt, offset, direction);

cxt.editor.tree.focus = current_view;
cxt.editor.ensure_cursor_in_view(current_view);

EventResult::Consumed(None)
}
Expand Down

0 comments on commit 475ce49

Please sign in to comment.