Skip to content

Commit e60266d

Browse files
committed
Ensure cursor is in view on window change
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`).
1 parent 41de475 commit e60266d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

helix-view/src/editor.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,9 +1223,11 @@ impl Editor {
12231223
pub fn focus(&mut self, view_id: ViewId) {
12241224
let prev_id = std::mem::replace(&mut self.tree.focus, view_id);
12251225

1226-
// if leaving the view: mode should reset
1226+
// if leaving the view: mode should reset and the cursor should be
1227+
// within view
12271228
if prev_id != view_id {
12281229
self.mode = Mode::Normal;
1230+
self.ensure_cursor_in_view(view_id);
12291231
}
12301232
}
12311233

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

1237-
// if leaving the view: mode should reset
1239+
// if leaving the view: mode should reset and the cursor should be
1240+
// within view
12381241
if prev_id != id {
12391242
self.mode = Mode::Normal;
1243+
self.ensure_cursor_in_view(id);
12401244
}
12411245
}
12421246

0 commit comments

Comments
 (0)