on master help sign in
Maintain the current cursor's position and view in the vsplit/hsplit commands too (#8109)
e8fc77fLorenzo Bellina
helix-term/src/commands.rs+9−7
@@ -4886,17 +4886,19 @@ fn transpose_view(cx: &mut Context) {
4886 cx.editor.transpose_view()
4886 cx.editor.transpose_view()
4887}
4887}
4888
4888
4889−// split helper, clear it later
4889+/// Open a new split in the given direction specified by the action.
4890+///
4891+/// Maintain the current view (both the cursor's position and view in document).
4890−fn split(cx: &mut Context, action: Action) {
4892+fn split(editor: &mut Editor, action: Action) {
4891− let (view, doc) = current!(cx.editor);
4893+ let (view, doc) = current!(editor);
4892 let id = doc.id();
4894 let id = doc.id();
4893 let selection = doc.selection(view.id).clone();
4895 let selection = doc.selection(view.id).clone();
4894 let offset = view.offset;
4896 let offset = view.offset;
4895
4897
4896− cx.editor.switch(id, action);
4898+ editor.switch(id, action);
4897
4899
4898 // match the selection in the previous view
4900 // match the selection in the previous view
4899− let (view, doc) = current!(cx.editor);
4901+ let (view, doc) = current!(editor);
4900 doc.set_selection(view.id, selection);
4902 doc.set_selection(view.id, selection);
4901 // match the view scroll offset (switch doesn't handle this fully
4903 // match the view scroll offset (switch doesn't handle this fully
4902 // since the selection is only matched after the split)
4904 // since the selection is only matched after the split)
@@ -4904,7 +4906,7 @@ fn split(cx: &mut Context, action: Action) {
4904}
4906}
4905
4907
4906fn hsplit(cx: &mut Context) {
4908fn hsplit(cx: &mut Context) {
4907− split(cx, Action::HorizontalSplit);
4909+ split(cx.editor, Action::HorizontalSplit);
4908}
4910}
4909
4911
4910fn hsplit_new(cx: &mut Context) {
4912fn hsplit_new(cx: &mut Context) {
@@ -4912,7 +4914,7 @@ fn hsplit_new(cx: &mut Context) {
4912}
4914}
4913
4915
4914fn vsplit(cx: &mut Context) {
4916fn vsplit(cx: &mut Context) {
4915− split(cx, Action::VerticalSplit);
4917+ split(cx.editor, Action::VerticalSplit);
4916}
4918}
4917
4919
4918fn vsplit_new(cx: &mut Context) {
4920fn vsplit_new(cx: &mut Context) {
helix-term/src/commands/typed.rs+2−6
@@ -1536,10 +1536,8 @@ fn vsplit(
1536 return Ok(());
1536 return Ok(());
1537 }
1537 }
1538
1538
1539− let id = view!(cx.editor).doc;
1540−
1541 if args.is_empty() {
1539 if args.is_empty() {
1542− cx.editor.switch(id, Action::VerticalSplit);
1540+ split(cx.editor, Action::VerticalSplit);
1543 } else {
1541 } else {
1544 for arg in args {
1542 for arg in args {
1545 cx.editor
1543 cx.editor
@@ -1559,10 +1557,8 @@ fn hsplit(
1559 return Ok(());
1557 return Ok(());
1560 }
1558 }
1561
1559
1562− let id = view!(cx.editor).doc;
1563−
1564 if args.is_empty() {
1560 if args.is_empty() {
1565− cx.editor.switch(id, Action::HorizontalSplit);
1561+ split(cx.editor, Action::HorizontalSplit);
1566 } else {
1562 } else {
1567 for arg in args {
1563 for arg in args {
1568 cx.editor
1564 cx.editor