From 3e0aefe2e1eb0e027157d4414c96f3c695b37261 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Sat, 3 Jun 2023 21:06:46 +0200 Subject: [PATCH 1/3] Maintain the current cursor's position and view in the vsplit/hsplit commands too Signed-off-by: Benjamin Bouvier --- helix-term/src/commands.rs | 16 +++++++++------- helix-term/src/commands/typed.rs | 8 ++------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 1f88079eb27d..bbe724219690 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -4828,17 +4828,19 @@ fn transpose_view(cx: &mut Context) { cx.editor.transpose_view() } -// split helper, clear it later -fn split(cx: &mut Context, action: Action) { - let (view, doc) = current!(cx.editor); +/// Open a new split in the given direction specified by the action. +/// +/// Maintain the current view (both the cursor's position and view in document). +fn split_helper(editor: &mut Editor, action: Action) { + let (view, doc) = current!(editor); let id = doc.id(); let selection = doc.selection(view.id).clone(); let offset = view.offset; - cx.editor.switch(id, action); + editor.switch(id, action); // match the selection in the previous view - let (view, doc) = current!(cx.editor); + let (view, doc) = current!(editor); doc.set_selection(view.id, selection); // match the view scroll offset (switch doesn't handle this fully // since the selection is only matched after the split) @@ -4846,7 +4848,7 @@ fn split(cx: &mut Context, action: Action) { } fn hsplit(cx: &mut Context) { - split(cx, Action::HorizontalSplit); + split_helper(&mut cx.editor, Action::HorizontalSplit); } fn hsplit_new(cx: &mut Context) { @@ -4854,7 +4856,7 @@ fn hsplit_new(cx: &mut Context) { } fn vsplit(cx: &mut Context) { - split(cx, Action::VerticalSplit); + split_helper(&mut cx.editor, Action::VerticalSplit); } fn vsplit_new(cx: &mut Context) { diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index a7eb22448078..a81dc020bab7 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -1538,10 +1538,8 @@ fn vsplit( return Ok(()); } - let id = view!(cx.editor).doc; - if args.is_empty() { - cx.editor.switch(id, Action::VerticalSplit); + split_helper(&mut cx.editor, Action::VerticalSplit); } else { for arg in args { cx.editor @@ -1561,10 +1559,8 @@ fn hsplit( return Ok(()); } - let id = view!(cx.editor).doc; - if args.is_empty() { - cx.editor.switch(id, Action::HorizontalSplit); + split_helper(&mut cx.editor, Action::HorizontalSplit); } else { for arg in args { cx.editor From ffed075422079bf6f7212fc18084b04cdda05d16 Mon Sep 17 00:00:00 2001 From: TheRealLorenz Date: Tue, 29 Aug 2023 19:32:39 +0200 Subject: [PATCH 2/3] Fix clippy error --- helix-term/src/commands.rs | 4 ++-- helix-term/src/commands/typed.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index bbe724219690..d4c022dd3aff 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -4848,7 +4848,7 @@ fn split_helper(editor: &mut Editor, action: Action) { } fn hsplit(cx: &mut Context) { - split_helper(&mut cx.editor, Action::HorizontalSplit); + split_helper(cx.editor, Action::HorizontalSplit); } fn hsplit_new(cx: &mut Context) { @@ -4856,7 +4856,7 @@ fn hsplit_new(cx: &mut Context) { } fn vsplit(cx: &mut Context) { - split_helper(&mut cx.editor, Action::VerticalSplit); + split_helper(cx.editor, Action::VerticalSplit); } fn vsplit_new(cx: &mut Context) { diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index a81dc020bab7..4f15932fe556 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -1539,7 +1539,7 @@ fn vsplit( } if args.is_empty() { - split_helper(&mut cx.editor, Action::VerticalSplit); + split_helper(cx.editor, Action::VerticalSplit); } else { for arg in args { cx.editor @@ -1560,7 +1560,7 @@ fn hsplit( } if args.is_empty() { - split_helper(&mut cx.editor, Action::HorizontalSplit); + split_helper(cx.editor, Action::HorizontalSplit); } else { for arg in args { cx.editor From 82d628fb52791389475700b64112fedb8e027b38 Mon Sep 17 00:00:00 2001 From: TheRealLorenz Date: Thu, 31 Aug 2023 09:43:57 +0200 Subject: [PATCH 3/3] Undo function rename --- helix-term/src/commands.rs | 6 +++--- helix-term/src/commands/typed.rs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index d4c022dd3aff..acf25957568f 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -4831,7 +4831,7 @@ fn transpose_view(cx: &mut Context) { /// Open a new split in the given direction specified by the action. /// /// Maintain the current view (both the cursor's position and view in document). -fn split_helper(editor: &mut Editor, action: Action) { +fn split(editor: &mut Editor, action: Action) { let (view, doc) = current!(editor); let id = doc.id(); let selection = doc.selection(view.id).clone(); @@ -4848,7 +4848,7 @@ fn split_helper(editor: &mut Editor, action: Action) { } fn hsplit(cx: &mut Context) { - split_helper(cx.editor, Action::HorizontalSplit); + split(cx.editor, Action::HorizontalSplit); } fn hsplit_new(cx: &mut Context) { @@ -4856,7 +4856,7 @@ fn hsplit_new(cx: &mut Context) { } fn vsplit(cx: &mut Context) { - split_helper(cx.editor, Action::VerticalSplit); + split(cx.editor, Action::VerticalSplit); } fn vsplit_new(cx: &mut Context) { diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 4f15932fe556..4978076c8c44 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -1539,7 +1539,7 @@ fn vsplit( } if args.is_empty() { - split_helper(cx.editor, Action::VerticalSplit); + split(cx.editor, Action::VerticalSplit); } else { for arg in args { cx.editor @@ -1560,7 +1560,7 @@ fn hsplit( } if args.is_empty() { - split_helper(cx.editor, Action::HorizontalSplit); + split(cx.editor, Action::HorizontalSplit); } else { for arg in args { cx.editor