From 07c5152078abf5c7f80bcebf2f26d45c49925210 Mon Sep 17 00:00:00 2001 From: Devin Singh Date: Sun, 22 Aug 2021 11:37:44 -0500 Subject: [PATCH 1/2] add vsplit and hsplit commands --- helix-term/src/commands.rs | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index a78f137a87db..83346e183b3e 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1900,6 +1900,38 @@ mod cmd { Ok(()) } + fn vsplit( + cx: &mut compositor::Context, + args: &[&str], + _event: PromptEvent, + ) -> anyhow::Result<()> { + let (_, doc) = current!(cx.editor); + let id = doc.id(); + + cx.editor.switch(id, Action::VerticalSplit); + + let path = args.get(0).context("wrong argument count")?; + + let _ = cx.editor.open(path.into(), Action::Replace)?; + Ok(()) + } + + fn hsplit( + cx: &mut compositor::Context, + args: &[&str], + _event: PromptEvent, + ) -> anyhow::Result<()> { + let (_, doc) = current!(cx.editor); + let id = doc.id(); + + cx.editor.switch(id, Action::HorizontalSplit); + + let path = args.get(0).context("wrong argument count")?; + + let _ = cx.editor.open(path.into(), Action::Replace)?; + Ok(()) + } + pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ TypableCommand { name: "quit", @@ -2138,6 +2170,20 @@ mod cmd { doc: "Display tree sitter scopes, primarily for theming and development.", fun: tree_sitter_scopes, completer: None, + }, + TypableCommand { + name: "vsplit", + alias: Some("vsp"), + doc: "Open the file in a vertical split.", + fun: vsplit, + completer: Some(completers::filename), + }, + TypableCommand { + name: "hsplit", + alias: Some("sp"), + doc: "Open the file in a horizontal split.", + fun: hsplit, + completer: Some(completers::filename), } ]; From 22c07afc1797bbc8b97a069f15b5809f4f3c76be Mon Sep 17 00:00:00 2001 From: Devin Singh Date: Mon, 23 Aug 2021 06:56:04 -0500 Subject: [PATCH 2/2] handle splits more elegantly --- helix-term/src/commands.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 83346e183b3e..56e4f1b6ea92 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1908,11 +1908,12 @@ mod cmd { let (_, doc) = current!(cx.editor); let id = doc.id(); - cx.editor.switch(id, Action::VerticalSplit); - - let path = args.get(0).context("wrong argument count")?; + if let Some(path) = args.get(0) { + cx.editor.open(path.into(), Action::VerticalSplit)?; + } else { + cx.editor.switch(id, Action::VerticalSplit); + } - let _ = cx.editor.open(path.into(), Action::Replace)?; Ok(()) } @@ -1924,11 +1925,12 @@ mod cmd { let (_, doc) = current!(cx.editor); let id = doc.id(); - cx.editor.switch(id, Action::HorizontalSplit); - - let path = args.get(0).context("wrong argument count")?; + if let Some(path) = args.get(0) { + cx.editor.open(path.into(), Action::HorizontalSplit)?; + } else { + cx.editor.switch(id, Action::HorizontalSplit); + } - let _ = cx.editor.open(path.into(), Action::Replace)?; Ok(()) }