diff options
Diffstat (limited to 'helix-view')
-rw-r--r-- | helix-view/src/editor.rs | 7 | ||||
-rw-r--r-- | helix-view/src/tree.rs | 8 | ||||
-rw-r--r-- | helix-view/src/view.rs | 1 |
3 files changed, 13 insertions, 3 deletions
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 7ac52f50..6cd4515c 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -874,7 +874,12 @@ impl Editor { return; } Action::HorizontalSplit | Action::VerticalSplit => { - let view = View::new(id, self.config().gutters.clone()); + // copy the current view, unless there is no view yet + let view = self + .tree + .try_get(self.tree.focus) + .cloned() + .unwrap_or_else(|| View::new(id, self.config().gutters.clone())); let view_id = self.tree.split( view, match action { diff --git a/helix-view/src/tree.rs b/helix-view/src/tree.rs index 3ba85b56..c4474c33 100644 --- a/helix-view/src/tree.rs +++ b/helix-view/src/tree.rs @@ -271,12 +271,16 @@ impl Tree { } pub fn get(&self, index: ViewId) -> &View { + self.try_get(index).unwrap() + } + + pub fn try_get(&self, index: ViewId) -> Option<&View> { match &self.nodes[index] { Node { content: Content::View(view), .. - } => view, - _ => unreachable!(), + } => Some(view), + _ => None, } } diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs index e74e0f65..e7fc16ab 100644 --- a/helix-view/src/view.rs +++ b/helix-view/src/view.rs @@ -64,6 +64,7 @@ impl JumpList { } } +#[derive(Clone)] pub struct View { pub id: ViewId, pub offset: Position, |