@@ -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