From 1e9e98bc906f8610614f9f9418ab1e988428423d Mon Sep 17 00:00:00 2001 From: Robin Date: Sun, 10 Jul 2022 16:56:40 +0200 Subject: [PATCH 1/2] keep jump/file history when using :split --- helix-term/src/commands.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 193d5d405fb2..95e5029d3544 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -3992,12 +3992,23 @@ fn split(cx: &mut Context, action: Action) { let id = doc.id(); let selection = doc.selection(view.id).clone(); let offset = view.offset; + let jumps = view.jumps.clone(); + let docs_access_history = view.docs_access_history.clone(); + let last_modified_docs = view.last_modified_docs; + let object_selections = view.object_selections.clone(); + let gutters = view.gutters.clone(); cx.editor.switch(id, action); // match the selection in the previous view let (view, doc) = current!(cx.editor); view.offset = offset; + view.jumps = jumps; + view.docs_access_history = docs_access_history; + view.last_modified_docs = last_modified_docs; + view.object_selections = object_selections; + view.gutters = gutters; + doc.set_selection(view.id, selection); } From 48e8b0161d5a03e96c91aa1a9a4b5cd67dd49d7a Mon Sep 17 00:00:00 2001 From: Robin Date: Tue, 12 Jul 2022 10:22:03 +0200 Subject: [PATCH 2/2] move history cloning into the switch function --- helix-term/src/commands.rs | 13 ------------- helix-view/src/editor.rs | 7 ++++++- helix-view/src/tree.rs | 8 ++++++-- helix-view/src/view.rs | 1 + 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 95e5029d3544..48d8113dad80 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -3991,24 +3991,11 @@ fn split(cx: &mut Context, action: Action) { let (view, doc) = current!(cx.editor); let id = doc.id(); let selection = doc.selection(view.id).clone(); - let offset = view.offset; - let jumps = view.jumps.clone(); - let docs_access_history = view.docs_access_history.clone(); - let last_modified_docs = view.last_modified_docs; - let object_selections = view.object_selections.clone(); - let gutters = view.gutters.clone(); cx.editor.switch(id, action); // match the selection in the previous view let (view, doc) = current!(cx.editor); - view.offset = offset; - view.jumps = jumps; - view.docs_access_history = docs_access_history; - view.last_modified_docs = last_modified_docs; - view.object_selections = object_selections; - view.gutters = gutters; - doc.set_selection(view.id, selection); } diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index a2943af98182..397f59628a5d 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -799,7 +799,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 3ba85b560f81..c4474c33cf41 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 bfae12a4465e..fb26bf50a349 100644 --- a/helix-view/src/view.rs +++ b/helix-view/src/view.rs @@ -60,6 +60,7 @@ impl JumpList { } } +#[derive(Clone)] pub struct View { pub id: ViewId, pub offset: Position,