Skip to content

Commit

Permalink
keep jump/file history when using :split (helix-editor#3031)
Browse files Browse the repository at this point in the history
* keep jump/file history when using :split

* move history cloning into the switch function

Co-authored-by: Robin <[email protected]>
  • Loading branch information
2 people authored and thomasskk committed Sep 9, 2022
1 parent cfcdcfd commit a1f85b7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
2 changes: 0 additions & 2 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4123,13 +4123,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;

cx.editor.switch(id, action);

// match the selection in the previous view
let (view, doc) = current!(cx.editor);
view.offset = offset;
doc.set_selection(view.id, selection);
}

Expand Down
7 changes: 6 additions & 1 deletion helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,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 {
Expand Down
8 changes: 6 additions & 2 deletions helix-view/src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
1 change: 1 addition & 0 deletions helix-view/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ impl JumpList {
}
}

#[derive(Clone)]
pub struct View {
pub id: ViewId,
pub offset: Position,
Expand Down

0 comments on commit a1f85b7

Please sign in to comment.