on master help sign in
keep jump/file history when using :split (#3031)

* keep jump/file history when using :split * move history cloning into the switch function Co-authored-by: Robin <robinvandijk@klippa.com>

commit19b7864062462e56545cfcca8402659573524f60 authorRobin <robin@robinjint.nl> dateFri 22 Jul 2022, 03:23 (4 years ago) parent2f53644
4 files changed+13−5
helix-term/src/commands.rs−2 helix-view/src/editor.rs+6−1 helix-view/src/tree.rs+6−2 helix-view/src/view.rs+1
helix-term/src/commands.rs−2
@@ -4083,13 +4083,11 @@ fn split(cx: &mut Context, action: Action) {
40834083 let (view, doc) = current!(cx.editor);
40844084 let id = doc.id();
40854085 let selection = doc.selection(view.id).clone();
4086− let offset = view.offset;
40874086
40884087 cx.editor.switch(id, action);
40894088
40904089 // match the selection in the previous view
40914090 let (view, doc) = current!(cx.editor);
4092− view.offset = offset;
40934091 doc.set_selection(view.id, selection);
40944092}
40954093
helix-view/src/editor.rs+6−1
@@ -874,7 +874,12 @@ impl Editor {
874874 return;
875875 }
876876 Action::HorizontalSplit | Action::VerticalSplit => {
877− let view = View::new(id, self.config().gutters.clone());
877+ // copy the current view, unless there is no view yet
878+ let view = self
879+ .tree
880+ .try_get(self.tree.focus)
881+ .cloned()
882+ .unwrap_or_else(|| View::new(id, self.config().gutters.clone()));
878883 let view_id = self.tree.split(
879884 view,
880885 match action {
helix-view/src/tree.rs+6−2
@@ -271,12 +271,16 @@ impl Tree {
271271 }
272272
273273 pub fn get(&self, index: ViewId) -> &View {
274+ self.try_get(index).unwrap()
275+ }
276+
277+ pub fn try_get(&self, index: ViewId) -> Option<&View> {
274278 match &self.nodes[index] {
275279 Node {
276280 content: Content::View(view),
277281 ..
278− } => view,
279− _ => unreachable!(),
282+ } => Some(view),
283+ _ => None,
280284 }
281285 }
282286
helix-view/src/view.rs+1
@@ -64,6 +64,7 @@ impl JumpList {
6464 }
6565}
6666
67+#[derive(Clone)]
6768pub struct View {
6869 pub id: ViewId,
6970 pub offset: Position,