on master help sign in
Factor out common code for focusing the next view (#4607)
b474ee1Michael Davis
helix-view/src/editor.rs+1−10
@@ -1243,16 +1243,7 @@ impl Editor {
1243 }
1243 }
1244
1244
1245 pub fn focus_next(&mut self) {
1245 pub fn focus_next(&mut self) {
1246− let prev_id = self.tree.focus;
1247− self.tree.focus_next();
1246+ self.focus(self.tree.next());
1248− let id = self.tree.focus;
1249−
1250− // if leaving the view: mode should reset and the cursor should be
1251− // within view
1252− if prev_id != id {
1253− self.mode = Mode::Normal;
1254− self.ensure_cursor_in_view(id);
1255− }
1256 }
1247 }
1257
1248
1258 pub fn focus_direction(&mut self, direction: tree::Direction) {
1249 pub fn focus_direction(&mut self, direction: tree::Direction) {
helix-view/src/tree.rs+4−4
@@ -219,7 +219,7 @@ impl Tree {
219
219
220 if self.focus == index {
220 if self.focus == index {
221 // focus on something else
221 // focus on something else
222− self.focus_next();
222+ self.focus = self.next();
223 }
223 }
224
224
225 stack.push(index);
225 stack.push(index);
@@ -521,7 +521,7 @@ impl Tree {
521 Some(child_id)
521 Some(child_id)
522 }
522 }
523
523
524− pub fn focus_next(&mut self) {
524+ pub fn next(&self) -> ViewId {
525 // This function is very dumb, but that's because we don't store any parent links.
525 // This function is very dumb, but that's because we don't store any parent links.
526 // (we'd be able to go parent.next_sibling() recursively until we find something)
526 // (we'd be able to go parent.next_sibling() recursively until we find something)
527 // For now that's okay though, since it's unlikely you'll be able to open a large enough
527 // For now that's okay though, since it's unlikely you'll be able to open a large enough
@@ -532,11 +532,11 @@ impl Tree {
532 .skip_while(|&(id, _view)| id != self.focus)
532 .skip_while(|&(id, _view)| id != self.focus)
533 .skip(1); // Skip focused value
533 .skip(1); // Skip focused value
534 if let Some((id, _)) = views.next() {
534 if let Some((id, _)) = views.next() {
535− self.focus = id;
535+ id
536 } else {
536 } else {
537 // extremely crude, take the first item again
537 // extremely crude, take the first item again
538 let (key, _) = self.traverse().next().unwrap();
538 let (key, _) = self.traverse().next().unwrap();
539− self.focus = key;
539+ key
540 }
540 }
541 }
541 }
542
542