Skip to content

Commit 6410e65

Browse files
committed
Update +N argument feature according to feedback in original PR helix-editor#5603
1 parent 66fbb60 commit 6410e65

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

helix-term/src/args.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ pub struct Args {
1818
pub config_file: Option<PathBuf>,
1919
pub files: Vec<(PathBuf, Position)>,
2020
pub working_directory: Option<PathBuf>,
21-
pub line_number: usize,
2221
}
2322

2423
impl Args {
2524
pub fn parse_args() -> Result<Args> {
2625
let mut args = Args::default();
2726
let mut argv = std::env::args().peekable();
27+
let mut line_number = 0;
2828

2929
argv.next(); // skip the program, we don't care about that
3030

@@ -90,14 +90,11 @@ impl Args {
9090
}
9191
}
9292
arg if arg.starts_with('+') => {
93-
let arg = arg.get(1..).unwrap();
94-
args.line_number = match arg.parse() {
95-
Ok(n) => n,
93+
let arg = &arg[1..];
94+
line_number = match arg.parse::<usize>() {
95+
Ok(n) => n.saturating_sub(1),
9696
_ => anyhow::bail!("bad line number after +"),
9797
};
98-
if args.line_number > 0 {
99-
args.line_number -= 1;
100-
}
10198
}
10299
arg => args.files.push(parse_file(arg)),
103100
}
@@ -109,7 +106,7 @@ impl Args {
109106
}
110107

111108
if let Some(file) = args.files.first_mut() {
112-
file.1.row = args.line_number;
109+
file.1.row = line_number;
113110
}
114111

115112
Ok(args)

helix-term/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ FLAGS:
6767
--vsplit Splits all given files vertically into different windows
6868
--hsplit Splits all given files horizontally into different windows
6969
-w, --working-dir <path> Specify an initial working directory
70-
+N Goto line number N
70+
+N Open the first given file at line number N
7171
",
7272
env!("CARGO_PKG_NAME"),
7373
VERSION_AND_GIT_HASH,

0 commit comments

Comments
 (0)