From acabf2b492a7edff491aca7b0e4818a6e2473355 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6ran=20Karl?= <3951388+JoeKar@users.noreply.github.com> Date: Sun, 13 Oct 2024 15:25:51 +0200 Subject: [PATCH] action/command: Align `vsplit` & `hsplit` to `tab`'s multiopen handling --- internal/action/command.go | 32 ++++++++++++++++++-------------- runtime/help/commands.md | 3 ++- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/internal/action/command.go b/internal/action/command.go index 3c14dea2..b5b9794f 100644 --- a/internal/action/command.go +++ b/internal/action/command.go @@ -501,7 +501,7 @@ func (h *BufPane) HelpCmd(args []string) { } } -// VSplitCmd opens a vertical split with file given in the first argument +// VSplitCmd opens one or more vertical splits with the files given as arguments // If no file is given, it opens an empty buffer in a new split func (h *BufPane) VSplitCmd(args []string) { if len(args) == 0 { @@ -510,16 +510,18 @@ func (h *BufPane) VSplitCmd(args []string) { return } - buf, err := buffer.NewBufferFromFile(args[0], buffer.BTDefault) - if err != nil { - InfoBar.Error(err) - return - } + for _, a := range args { + buf, err := buffer.NewBufferFromFile(a, buffer.BTDefault) + if err != nil { + InfoBar.Error(err) + return + } - h.VSplitBuf(buf) + h.VSplitBuf(buf) + } } -// HSplitCmd opens a horizontal split with file given in the first argument +// HSplitCmd opens one or more horizontal splits with the files given as arguments // If no file is given, it opens an empty buffer in a new split func (h *BufPane) HSplitCmd(args []string) { if len(args) == 0 { @@ -528,13 +530,15 @@ func (h *BufPane) HSplitCmd(args []string) { return } - buf, err := buffer.NewBufferFromFile(args[0], buffer.BTDefault) - if err != nil { - InfoBar.Error(err) - return - } + for _, a := range args { + buf, err := buffer.NewBufferFromFile(a, buffer.BTDefault) + if err != nil { + InfoBar.Error(err) + return + } - h.HSplitBuf(buf) + h.HSplitBuf(buf) + } } // EvalCmd evaluates a lua expression diff --git a/runtime/help/commands.md b/runtime/help/commands.md index 7d71d785..c406d740 100644 --- a/runtime/help/commands.md +++ b/runtime/help/commands.md @@ -76,7 +76,8 @@ quotes here but these are not necessary when entering the command in micro. command's output will be displayed in one line when it finishes running. * `vsplit ['filename']`: opens a vertical split with `filename`. If no filename - is provided, a vertical split is opened with an empty buffer. + is provided, a vertical split is opened with an empty buffer. If multiple + files are provided (separated via ` `) they are opened all as splits. * `hsplit ['filename']`: same as `vsplit` but opens a horizontal split instead of a vertical split.