on master help sign in
keep jump/file history when using :split (#3031)
19b7864Robin
helix-term/src/commands.rs−2
@@ -4083,13 +4083,11 @@ fn split(cx: &mut Context, action: Action) {
4083 let (view, doc) = current!(cx.editor);
4083 let (view, doc) = current!(cx.editor);
4084 let id = doc.id();
4084 let id = doc.id();
4085 let selection = doc.selection(view.id).clone();
4085 let selection = doc.selection(view.id).clone();
4086− let offset = view.offset;
4087
4086
4088 cx.editor.switch(id, action);
4087 cx.editor.switch(id, action);
4089
4088
4090 // match the selection in the previous view
4089 // match the selection in the previous view
4091 let (view, doc) = current!(cx.editor);
4090 let (view, doc) = current!(cx.editor);
4092− view.offset = offset;
4093 doc.set_selection(view.id, selection);
4091 doc.set_selection(view.id, selection);
4094}
4092}
4095
4093
helix-view/src/editor.rs+6−1
@@ -874,7 +874,12 @@ impl Editor {
874 return;
874 return;
875 }
875 }
876 Action::HorizontalSplit | Action::VerticalSplit => {
876 Action::HorizontalSplit | Action::VerticalSplit => {
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()
877− let view = View::new(id, self.config().gutters.clone());
882+ .unwrap_or_else(|| View::new(id, self.config().gutters.clone()));
878 let view_id = self.tree.split(
883 let view_id = self.tree.split(
879 view,
884 view,
880 match action {
885 match action {
helix-view/src/tree.rs+6−2
@@ -271,12 +271,16 @@ impl Tree {
271 }
271 }
272
272
273 pub fn get(&self, index: ViewId) -> &View {
273 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> {
274 match &self.nodes[index] {
278 match &self.nodes[index] {
275 Node {
279 Node {
276 content: Content::View(view),
280 content: Content::View(view),
277 ..
281 ..
278− } => view,
282+ } => Some(view),
279− _ => unreachable!(),
283+ _ => None,
280 }
284 }
281 }
285 }
282
286
helix-view/src/view.rs+1
@@ -64,6 +64,7 @@ impl JumpList {
64 }
64 }
65}
65}
66
66
67+#[derive(Clone)]
67pub struct View {
68pub struct View {
68 pub id: ViewId,
69 pub id: ViewId,
69 pub offset: Position,
70 pub offset: Position,