mirror of https://github.com/helix-editor/helix
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>pull/2470/head^2
parent
2f53644c6d
commit
19b7864062
|
@ -4083,13 +4083,11 @@ fn split(cx: &mut Context, action: Action) {
|
||||||
let (view, doc) = current!(cx.editor);
|
let (view, doc) = current!(cx.editor);
|
||||||
let id = doc.id();
|
let id = doc.id();
|
||||||
let selection = doc.selection(view.id).clone();
|
let selection = doc.selection(view.id).clone();
|
||||||
let offset = view.offset;
|
|
||||||
|
|
||||||
cx.editor.switch(id, action);
|
cx.editor.switch(id, action);
|
||||||
|
|
||||||
// match the selection in the previous view
|
// match the selection in the previous view
|
||||||
let (view, doc) = current!(cx.editor);
|
let (view, doc) = current!(cx.editor);
|
||||||
view.offset = offset;
|
|
||||||
doc.set_selection(view.id, selection);
|
doc.set_selection(view.id, selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -874,7 +874,12 @@ impl Editor {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Action::HorizontalSplit | Action::VerticalSplit => {
|
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(
|
let view_id = self.tree.split(
|
||||||
view,
|
view,
|
||||||
match action {
|
match action {
|
||||||
|
|
|
@ -271,12 +271,16 @@ impl Tree {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(&self, index: ViewId) -> &View {
|
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] {
|
match &self.nodes[index] {
|
||||||
Node {
|
Node {
|
||||||
content: Content::View(view),
|
content: Content::View(view),
|
||||||
..
|
..
|
||||||
} => view,
|
} => Some(view),
|
||||||
_ => unreachable!(),
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,6 +64,7 @@ impl JumpList {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct View {
|
pub struct View {
|
||||||
pub id: ViewId,
|
pub id: ViewId,
|
||||||
pub offset: Position,
|
pub offset: Position,
|
||||||
|
|
Loading…
Reference in New Issue