Skip to content

Commit

Permalink
Ensure cursor is in view on window change
Browse files Browse the repository at this point in the history
If two windows are editing the same document, one may delete enough of
the document so that the other window is pointing at a blank page (past
the document end). In this change we ensure that the cursor is within
view whenever we switch to a new window (for example with `<C-w>w`).
  • Loading branch information
the-mikedavis committed Nov 3, 2022
1 parent 41de475 commit e60266d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1223,9 +1223,11 @@ impl Editor {
pub fn focus(&mut self, view_id: ViewId) {
let prev_id = std::mem::replace(&mut self.tree.focus, view_id);

// if leaving the view: mode should reset
// if leaving the view: mode should reset and the cursor should be
// within view
if prev_id != view_id {
self.mode = Mode::Normal;
self.ensure_cursor_in_view(view_id);
}
}

Expand All @@ -1234,9 +1236,11 @@ impl Editor {
self.tree.focus_next();
let id = self.tree.focus;

// if leaving the view: mode should reset
// if leaving the view: mode should reset and the cursor should be
// within view
if prev_id != id {
self.mode = Mode::Normal;
self.ensure_cursor_in_view(id);
}
}

Expand Down

0 comments on commit e60266d

Please sign in to comment.