aboutsummaryrefslogtreecommitdiff
path: root/helix-view
diff options
context:
space:
mode:
authorMichael Davis2022-11-17 00:59:59 +0000
committerGitHub2022-11-17 00:59:59 +0000
commitb474ee1843d5cb7cb5291bee4166490a223e5aac (patch)
tree612c8c4925d4e212822d3af9631c9c78e36207c7 /helix-view
parent6eec14ee3726fc46850025ea1e184ecf74db5cf4 (diff)
Factor out common code for focusing the next view (#4607)
There is some common code between Editor::focus_next and Editor::focus that can be eliminated by refactoring Tree::focus_next into a function that only returns the next ViewId.
Diffstat (limited to 'helix-view')
-rw-r--r--helix-view/src/editor.rs11
-rw-r--r--helix-view/src/tree.rs8
2 files changed, 5 insertions, 14 deletions
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index 4e3a69a2..23e0a497 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -1243,16 +1243,7 @@ impl Editor {
}
pub fn focus_next(&mut self) {
- let prev_id = self.tree.focus;
- self.tree.focus_next();
- let id = self.tree.focus;
-
- // 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);
- }
+ self.focus(self.tree.next());
}
pub fn focus_direction(&mut self, direction: tree::Direction) {
diff --git a/helix-view/src/tree.rs b/helix-view/src/tree.rs
index 6174021c..40484024 100644
--- a/helix-view/src/tree.rs
+++ b/helix-view/src/tree.rs
@@ -219,7 +219,7 @@ impl Tree {
if self.focus == index {
// focus on something else
- self.focus_next();
+ self.focus = self.next();
}
stack.push(index);
@@ -521,7 +521,7 @@ impl Tree {
Some(child_id)
}
- pub fn focus_next(&mut self) {
+ pub fn next(&self) -> ViewId {
// This function is very dumb, but that's because we don't store any parent links.
// (we'd be able to go parent.next_sibling() recursively until we find something)
// 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 {
.skip_while(|&(id, _view)| id != self.focus)
.skip(1); // Skip focused value
if let Some((id, _)) = views.next() {
- self.focus = id;
+ id
} else {
// extremely crude, take the first item again
let (key, _) = self.traverse().next().unwrap();
- self.focus = key;
+ key
}
}