on master help sign in
minor: Refactor commands.rs a bit more
commitcbd39d67a419aa0442af6d81b5b41ad518dc5fff authorBlaž Hrastnik <blaz@mxxn.io> dateFri 20 Aug 2021, 10:30 (5 years ago) parentda88108
2 files changed+11−10
helix-term/src/commands.rs+10−9 helix-term/src/ui/mod.rs+1−1
helix-term/src/commands.rs+10−9
@@ -888,7 +888,7 @@ pub fn scroll(cx: &mut Context, offset: usize, direction: Direction) {
888888 .primary()
889889 .cursor(doc.text().slice(..)),
890890 );
891− let doc_last_line = doc.text().len_lines() - 1;
891+ let doc_last_line = doc.text().len_lines().saturating_sub(1);
892892
893893 let last_line = view.last_line(doc);
894894
@@ -1509,18 +1509,19 @@ mod cmd {
15091509 return Ok(());
15101510 }
15111511
1512+ let arg = args.get(0).context("argument missing")?.to_ascii_lowercase();
1513+
15121514 // Attempt to parse argument as a line ending.
1513− let line_ending = match args.get(0) {
1515+ let line_ending = match arg {
15141516 // We check for CR first because it shares a common prefix with CRLF.
1515− Some(arg) if "cr".starts_with(&arg.to_lowercase()) => Some(CR),
1516− Some(arg) if "crlf".starts_with(&arg.to_lowercase()) => Some(Crlf),
1517− Some(arg) if "lf".starts_with(&arg.to_lowercase()) => Some(LF),
1518− Some(arg) if "ff".starts_with(&arg.to_lowercase()) => Some(FF),
1519− Some(arg) if "nel".starts_with(&arg.to_lowercase()) => Some(Nel),
1520− _ => None,
1517+ arg if arg.starts_with("cr") => CR,
1518+ arg if arg.starts_with("crlf") => Crlf,
1519+ arg if arg.starts_with("lf") => LF,
1520+ arg if arg.starts_with("ff") => FF,
1521+ arg if arg.starts_with("nel") => Nel,
1522+ _ => bail!("invalid line ending")
15211523 };
15221524
1523− let line_ending = line_ending.context("invalid line ending")?;
15241525 doc_mut!(cx.editor).line_ending = line_ending;
15251526 Ok(())
15261527 }
helix-term/src/ui/mod.rs+1−1
@@ -76,7 +76,7 @@ pub fn regex_prompt(
7676pub fn file_picker(root: PathBuf) -> FilePicker<PathBuf> {
7777 use ignore::Walk;
7878 use std::time;
79− let files = Walk::new(root.clone()).filter_map(|entry| {
79+ let files = Walk::new(&root).filter_map(|entry| {
8080 let entry = entry.ok()?;
8181 // Path::is_dir() traverses symlinks, so we use it over DirEntry::is_dir
8282 if entry.path().is_dir() {