mirror of https://github.com/helix-editor/helix
Maintain the current cursor's position and view in the vsplit/hsplit commands too (#8109)
Co-authored-by: Benjamin Bouvier <public@benj.me>pull/8161/head
parent
bb3e6998e6
commit
e8fc77fe98
|
@ -4886,17 +4886,19 @@ fn transpose_view(cx: &mut Context) {
|
||||||
cx.editor.transpose_view()
|
cx.editor.transpose_view()
|
||||||
}
|
}
|
||||||
|
|
||||||
// split helper, clear it later
|
/// Open a new split in the given direction specified by the action.
|
||||||
fn split(cx: &mut Context, action: Action) {
|
///
|
||||||
let (view, doc) = current!(cx.editor);
|
/// Maintain the current view (both the cursor's position and view in document).
|
||||||
|
fn split(editor: &mut Editor, action: Action) {
|
||||||
|
let (view, doc) = current!(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;
|
let offset = view.offset;
|
||||||
|
|
||||||
cx.editor.switch(id, action);
|
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!(editor);
|
||||||
doc.set_selection(view.id, selection);
|
doc.set_selection(view.id, selection);
|
||||||
// match the view scroll offset (switch doesn't handle this fully
|
// match the view scroll offset (switch doesn't handle this fully
|
||||||
// since the selection is only matched after the split)
|
// since the selection is only matched after the split)
|
||||||
|
@ -4904,7 +4906,7 @@ fn split(cx: &mut Context, action: Action) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hsplit(cx: &mut Context) {
|
fn hsplit(cx: &mut Context) {
|
||||||
split(cx, Action::HorizontalSplit);
|
split(cx.editor, Action::HorizontalSplit);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hsplit_new(cx: &mut Context) {
|
fn hsplit_new(cx: &mut Context) {
|
||||||
|
@ -4912,7 +4914,7 @@ fn hsplit_new(cx: &mut Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn vsplit(cx: &mut Context) {
|
fn vsplit(cx: &mut Context) {
|
||||||
split(cx, Action::VerticalSplit);
|
split(cx.editor, Action::VerticalSplit);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn vsplit_new(cx: &mut Context) {
|
fn vsplit_new(cx: &mut Context) {
|
||||||
|
|
|
@ -1536,10 +1536,8 @@ fn vsplit(
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let id = view!(cx.editor).doc;
|
|
||||||
|
|
||||||
if args.is_empty() {
|
if args.is_empty() {
|
||||||
cx.editor.switch(id, Action::VerticalSplit);
|
split(cx.editor, Action::VerticalSplit);
|
||||||
} else {
|
} else {
|
||||||
for arg in args {
|
for arg in args {
|
||||||
cx.editor
|
cx.editor
|
||||||
|
@ -1559,10 +1557,8 @@ fn hsplit(
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let id = view!(cx.editor).doc;
|
|
||||||
|
|
||||||
if args.is_empty() {
|
if args.is_empty() {
|
||||||
cx.editor.switch(id, Action::HorizontalSplit);
|
split(cx.editor, Action::HorizontalSplit);
|
||||||
} else {
|
} else {
|
||||||
for arg in args {
|
for arg in args {
|
||||||
cx.editor
|
cx.editor
|
||||||
|
|
Loading…
Reference in New Issue