on master help sign in
adds --vsplit and --hsplit arguments (#2773)

* adds --vsplit and --hsplit arguments * moved comment * fixed lint (third time's a charm) * changed vsplit and hsplit from two separate bools to type Option<Layout>, and some cleanup

commitf10b6f6ee2bbf4d6d9356e27be25b25bdb85b9cd authorplexom <48958093+plexom@users.noreply.github.com> dateFri 1 Jul 2022, 11:27 (4 years ago) parent15d96c8
6 files changed+29−5
contrib/completion/hx.bash+1−1 contrib/completion/hx.fish+2−1 contrib/completion/hx.zsh+2 helix-term/src/application.rs+18−3 helix-term/src/args.rs+4 helix-term/src/main.rs+2
contrib/completion/hx.bash+1−1
@@ -16,7 +16,7 @@ _hx() {
1616 COMPREPLY=($(compgen -W "$languages" -- $2))
1717 ;;
1818 *)
19− COMPREPLY=($(compgen -fd -W "-h --help --tutor -V --version -v -vv -vvv --health -g --grammar" -- $2))
19+ COMPREPLY=($(compgen -fd -W "-h --help --tutor -V --version -v -vv -vvv --health -g --grammar --vsplit --hsplit" -- $2))
2020 ;;
2121 esac
2222} && complete -F _hx hx
contrib/completion/hx.fish+2−1
@@ -9,4 +9,5 @@ complete -c hx -l health -x -a "$langs" -d "Checks for errors in editor setup"
99complete -c hx -s g -l grammar -x -a "fetch build" -d "Fetches or builds tree-sitter grammars"
1010complete -c hx -s v -o vv -o vvv -d "Increases logging verbosity"
1111complete -c hx -s V -l version -d "Prints version information"
12−
12+complete -c hx -l vsplit -d "Splits all given files vertically into different windows"
13+complete -c hx -l hsplit -d "Splits all given files horizontally into different windows"
contrib/completion/hx.zsh+2
@@ -14,6 +14,8 @@ _hx() {
1414 "--health[Checks for errors in editor setup]:language:->health" \
1515 "-g[Fetches or builds tree-sitter grammars]:action:->grammar" \
1616 "--grammar[Fetches or builds tree-sitter grammars]:action:->grammar" \
17+ "--vsplit[Splits all given files vertically into different windows]" \
18+ "--hsplit[Splits all given files horizontally into different windows]" \
1719 "*:file:_files"
1820
1921 case "$state" in
helix-term/src/application.rs+18−3
@@ -5,7 +5,7 @@ use helix_core::{
55 pos_at_coords, syntax, Selection,
66};
77use helix_lsp::{lsp, util::lsp_pos_to_pos, LspProgressMap};
8−use helix_view::{align_view, editor::ConfigEvent, theme, Align, Editor};
8+use helix_view::{align_view, editor::ConfigEvent, theme, tree::Layout, Align, Editor};
99use serde_json::json;
1010
1111use crate::{
@@ -158,16 +158,31 @@ impl Application {
158158 } else {
159159 let nr_of_files = args.files.len();
160160 editor.open(first, Action::VerticalSplit)?;
161− for (file, pos) in args.files {
161+ // Because the line above already opens the first file, we can
162+ // simply skip opening it a second time by using .skip(1) here.
163+ for (file, pos) in args.files.into_iter().skip(1) {
162164 if file.is_dir() {
163165 return Err(anyhow::anyhow!(
164166 "expected a path to file, found a directory. (to open a directory pass it as first argument)"
165167 ));
166168 } else {
169+ // If the user passes in either `--vsplit` or
170+ // `--hsplit` as a command line argument, all the given
171+ // files will be opened according to the selected
172+ // option. If neither of those two arguments are passed
173+ // in, just load the files normally.
174+ let action = match args.split {
175+ Some(Layout::Vertical) => Action::VerticalSplit,
176+ Some(Layout::Horizontal) => Action::HorizontalSplit,
177+ None => Action::Load,
178+ };
167179 let doc_id = editor
168− .open(&file, Action::Load)
180+ .open(&file, action)
169181 .context(format!("open '{}'", file.to_string_lossy()))?;
170182 // with Action::Load all documents have the same view
183+ // NOTE: this isn't necessarily true anymore. If
184+ // `--vsplit` or `--hsplit` are used, the file which is
185+ // opened last is focused on.
171186 let view_id = editor.tree.focus;
172187 let doc = editor.document_mut(doc_id).unwrap();
173188 let pos = Selection::point(pos_at_coords(doc.text().slice(..), pos, true));
helix-term/src/args.rs+4
@@ -1,5 +1,6 @@
11use anyhow::Result;
22use helix_core::Position;
3+use helix_view::tree::Layout;
34use std::path::{Path, PathBuf};
45
56#[derive(Default)]
@@ -11,6 +12,7 @@ pub struct Args {
1112 pub load_tutor: bool,
1213 pub fetch_grammars: bool,
1314 pub build_grammars: bool,
15+ pub split: Option<Layout>,
1416 pub verbosity: u64,
1517 pub files: Vec<(PathBuf, Position)>,
1618}
@@ -28,6 +30,8 @@ impl Args {
2830 "--version" => args.display_version = true,
2931 "--help" => args.display_help = true,
3032 "--tutor" => args.load_tutor = true,
33+ "--vsplit" => args.split = Some(Layout::Vertical),
34+ "--hsplit" => args.split = Some(Layout::Horizontal),
3135 "--health" => {
3236 args.health = true;
3337 args.health_arg = argv.next_if(|opt| !opt.starts_with('-'));
helix-term/src/main.rs+2
@@ -67,6 +67,8 @@ FLAGS:
6767 -v Increases logging verbosity each use for up to 3 times
6868 (default file: {})
6969 -V, --version Prints version information
70+ --vsplit Splits all given files vertically into different windows
71+ --hsplit Splits all given files horizontally into different windows
7072",
7173 env!("CARGO_PKG_NAME"),
7274 env!("VERSION_AND_GIT_HASH"),