From eab5cbd3ce7012949bab0567ae63f5926ff1d995 Mon Sep 17 00:00:00 2001 From: TornaxO7 Date: Tue, 12 Dec 2023 22:29:56 +0100 Subject: [PATCH 01/20] adding `shellexpand` and extend `surround_chars` --- Cargo.lock | 59 ++++++++++++++++++++++++++++++++++++++ helix-term/Cargo.toml | 5 +++- helix-term/src/commands.rs | 22 ++++++++------ 3 files changed, 77 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ea007bd4d3b5..6033a6f7aed1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -350,6 +350,27 @@ dependencies = [ "syn 2.0.38", ] +[[package]] +name = "dirs" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys 0.48.0", +] + [[package]] name = "dunce" version = "1.0.4" @@ -1180,6 +1201,7 @@ dependencies = [ "pulldown-cmark", "serde", "serde_json", + "shellexpand", "signal-hook", "signal-hook-tokio", "smallvec", @@ -1400,6 +1422,17 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "libredox" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85c833ca1e66078851dba29046874e38f08b2c883700aa29a03ddd3b23814ee8" +dependencies = [ + "bitflags 2.4.1", + "libc", + "redox_syscall 0.4.1", +] + [[package]] name = "link-cplusplus" version = "1.0.8" @@ -1574,6 +1607,12 @@ dependencies = [ "pathdiff", ] +[[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + [[package]] name = "parking_lot" version = "0.12.1" @@ -1723,6 +1762,17 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "redox_users" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a18479200779601e498ada4e8c1e1f50e3ee19deb0259c25825a98b5603b2cb4" +dependencies = [ + "getrandom", + "libredox", + "thiserror", +] + [[package]] name = "regex" version = "1.10.2" @@ -1865,6 +1915,15 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012" +[[package]] +name = "shellexpand" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da03fa3b94cc19e3ebfc88c4229c49d8f08cdbd1228870a45f0ffdf84988e14b" +dependencies = [ + "dirs", +] + [[package]] name = "signal-hook" version = "0.3.17" diff --git a/helix-term/Cargo.toml b/helix-term/Cargo.toml index ac5a8475d080..c07e5d5e0dfd 100644 --- a/helix-term/Cargo.toml +++ b/helix-term/Cargo.toml @@ -71,7 +71,10 @@ serde = { version = "1.0", features = ["derive"] } grep-regex = "0.1.12" grep-searcher = "0.1.13" -[target.'cfg(not(windows))'.dependencies] # https://github.com/vorner/signal-hook/issues/100 +# expand env-variables in paths +shellexpand = "3.1" + +[target.'cfg(not(windows))'.dependencies] # https://github.com/vorner/signal-hook/issues/100 signal-hook-tokio = { version = "0.3", features = ["futures-v0_3"] } libc = "0.2.150" diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index e557977adf88..75291abc79ce 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1176,6 +1176,8 @@ fn goto_file_impl(cx: &mut Context, action: Action) { let primary = selections.primary(); // Checks whether there is only one selection with a width of 1 if selections.len() == 1 && primary.len() == 1 { + paths.clear(); + let count = cx.count(); let text_slice = text.slice(..); // In this case it selects the WORD under the cursor @@ -1187,14 +1189,18 @@ fn goto_file_impl(cx: &mut Context, action: Action) { true, ); // Trims some surrounding chars so that the actual file is opened. - let surrounding_chars: &[_] = &['\'', '"', '(', ')']; - paths.clear(); - paths.push( - current_word - .fragment(text_slice) - .trim_matches(surrounding_chars) - .to_string(), - ); + let surrounding_chars: &[_] = &['\'', '"', '(', ')', ',', ';', '{', '}', '[', ']']; + let path = current_word + .fragment(text_slice) + .trim_matches(surrounding_chars) + .to_string(); + + match shellexpand::full(&path) { + Ok(path) => paths.push(path.to_string()), + Err(e) => { + cx.editor.set_error(format!("{}", e)); + } + } } for sel in paths { From 0fdbc66cf8065a48b0c011a2ed3a3695d2400a18 Mon Sep 17 00:00:00 2001 From: TornaxO7 Date: Tue, 12 Dec 2023 22:34:38 +0100 Subject: [PATCH 02/20] goto-file-path: adding test with ending character --- helix-term/tests/test/commands.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/helix-term/tests/test/commands.rs b/helix-term/tests/test/commands.rs index e52b142c6b68..743abd95720a 100644 --- a/helix-term/tests/test/commands.rs +++ b/helix-term/tests/test/commands.rs @@ -153,6 +153,17 @@ async fn test_goto_file_impl() -> anyhow::Result<()> { ) .await?; + // ';' is behind the path + test_key_sequence( + &mut AppBuilder::new().with_file(file.path(), None).build()?, + Some("iimport 'one.js';hgf"), + Some(&|app| { + assert_eq!(1, match_paths(app, vec!["one.js"])); + }), + false, + ) + .await?; + Ok(()) } From 5f83d91661c4134ec2c3b1b52756b41505106e92 Mon Sep 17 00:00:00 2001 From: TornaxO7 Date: Tue, 12 Dec 2023 22:36:58 +0100 Subject: [PATCH 03/20] reformat code --- helix-term/src/commands.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 75291abc79ce..21c2c0bf7b88 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1197,10 +1197,8 @@ fn goto_file_impl(cx: &mut Context, action: Action) { match shellexpand::full(&path) { Ok(path) => paths.push(path.to_string()), - Err(e) => { - cx.editor.set_error(format!("{}", e)); - } - } + Err(e) => cx.editor.set_error(format!("{}", e)), + }; } for sel in paths { From df34a6abe31530adf26c7a127261794b85046bd1 Mon Sep 17 00:00:00 2001 From: TornaxO7 Date: Wed, 13 Dec 2023 22:20:56 +0100 Subject: [PATCH 04/20] improving char collection for path --- helix-term/src/commands.rs | 49 +++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 21c2c0bf7b88..1c45426f569f 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1178,22 +1178,39 @@ fn goto_file_impl(cx: &mut Context, action: Action) { if selections.len() == 1 && primary.len() == 1 { paths.clear(); - let count = cx.count(); - let text_slice = text.slice(..); - // In this case it selects the WORD under the cursor - let current_word = textobject::textobject_word( - text_slice, - primary, - textobject::TextObject::Inside, - count, - true, - ); - // Trims some surrounding chars so that the actual file is opened. - let surrounding_chars: &[_] = &['\'', '"', '(', ')', ',', ';', '{', '}', '[', ']']; - let path = current_word - .fragment(text_slice) - .trim_matches(surrounding_chars) - .to_string(); + let is_valid_path_char = |c: &char| { + let valid_chars: &[char] = if cfg!(target_os = "windows") { + &[ + '@', '/', '\\', '.', '-', '_', '+', ',', '#', '$', '%', '{', '}', '[', ']', + ':', '!', '~', '=', + ] + } else { + &['@', '/', '.', '-', '_', '+', ',', '#', '$', '%', '~', '='] + }; + valid_chars.contains(&c) || c.is_alphabetic() + }; + + let path = { + let cursor = primary.cursor(text.slice(..)); + + let head = text + .chars_at(cursor) + .reversed() + .fold(Vec::new(), |mut acc, c| { + acc.push(c); + acc + }) + .into_iter() + .rev() + .collect::(); + + let tail = text + .chars_at(cursor) + .take_while(is_valid_path_char) + .collect::(); + + format!("{}{}", head, tail) + }; match shellexpand::full(&path) { Ok(path) => paths.push(path.to_string()), From 264cd2b91558d56c32d82d52fb03d759a08c53c2 Mon Sep 17 00:00:00 2001 From: TornaxO7 Date: Wed, 13 Dec 2023 22:56:17 +0100 Subject: [PATCH 05/20] add heuristic if cursor is on invalid char --- helix-term/src/commands.rs | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 1c45426f569f..5911647da68d 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1191,26 +1191,35 @@ fn goto_file_impl(cx: &mut Context, action: Action) { }; let path = { - let cursor = primary.cursor(text.slice(..)); + let start = { + let cursor_pos = primary.cursor(text.slice(..)); - let head = text - .chars_at(cursor) + let pre_cursor_pos = cursor_pos.saturating_sub(1); + let post_cursor_pos = cursor_pos.saturating_add(1); + + if is_valid_path_char(&text.char(cursor_pos)) { + text.chars_at(cursor_pos) + } else if is_valid_path_char(&text.char(pre_cursor_pos)) { + text.chars_at(pre_cursor_pos) + } else { + text.chars_at(post_cursor_pos) + } + }; + + let head = start + .clone() .reversed() - .fold(Vec::new(), |mut acc, c| { - acc.push(c); - acc - }) - .into_iter() + .take_while(is_valid_path_char) + .collect::() + .chars() .rev() .collect::(); - let tail = text - .chars_at(cursor) - .take_while(is_valid_path_char) - .collect::(); + let tail = start.take_while(is_valid_path_char).collect::(); format!("{}{}", head, tail) }; + log::debug!("Goto file path: {}", path); match shellexpand::full(&path) { Ok(path) => paths.push(path.to_string()), From a88c86d31b1e42eaa3fb465152f09bf043fe9b62 Mon Sep 17 00:00:00 2001 From: TornaxO7 Date: Wed, 13 Dec 2023 23:01:34 +0100 Subject: [PATCH 06/20] fix test --- helix-term/tests/test/commands.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-term/tests/test/commands.rs b/helix-term/tests/test/commands.rs index 743abd95720a..2d635ba342d1 100644 --- a/helix-term/tests/test/commands.rs +++ b/helix-term/tests/test/commands.rs @@ -156,7 +156,7 @@ async fn test_goto_file_impl() -> anyhow::Result<()> { // ';' is behind the path test_key_sequence( &mut AppBuilder::new().with_file(file.path(), None).build()?, - Some("iimport 'one.js';hgf"), + Some("iimport 'one.js';B;gf"), Some(&|app| { assert_eq!(1, match_paths(app, vec!["one.js"])); }), From 1753c6956d983662e9ed7c3ce10315b826a507c4 Mon Sep 17 00:00:00 2001 From: TornaxO7 Date: Wed, 13 Dec 2023 23:07:16 +0100 Subject: [PATCH 07/20] make clippy happy --- helix-term/src/commands.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 5911647da68d..8ac8c0bd8783 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1187,7 +1187,7 @@ fn goto_file_impl(cx: &mut Context, action: Action) { } else { &['@', '/', '.', '-', '_', '+', ',', '#', '$', '%', '~', '='] }; - valid_chars.contains(&c) || c.is_alphabetic() + valid_chars.contains(c) || c.is_alphabetic() }; let path = { From 0da3262702f2a350f59a03a7d1e958fd47833057 Mon Sep 17 00:00:00 2001 From: TornaxO7 Date: Wed, 13 Dec 2023 23:40:03 +0100 Subject: [PATCH 08/20] removing `,` from the accepted file paths --- helix-term/src/commands.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 8ac8c0bd8783..ec5f041b9725 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1181,11 +1181,11 @@ fn goto_file_impl(cx: &mut Context, action: Action) { let is_valid_path_char = |c: &char| { let valid_chars: &[char] = if cfg!(target_os = "windows") { &[ - '@', '/', '\\', '.', '-', '_', '+', ',', '#', '$', '%', '{', '}', '[', ']', - ':', '!', '~', '=', + '@', '/', '\\', '.', '-', '_', '+', '#', '$', '%', '{', '}', '[', ']', ':', + '!', '~', '=', ] } else { - &['@', '/', '.', '-', '_', '+', ',', '#', '$', '%', '~', '='] + &['@', '/', '.', '-', '_', '+', '#', '$', '%', '~', '='] }; valid_chars.contains(c) || c.is_alphabetic() }; From 014a1521cd68a902e71a9de23efc31f03c983541 Mon Sep 17 00:00:00 2001 From: TornaxO7 Date: Thu, 11 Jan 2024 18:29:41 +0100 Subject: [PATCH 09/20] goto-file: improve head and tail detection --- helix-term/src/commands.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index ec5f041b9725..9a8479f1184e 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1191,9 +1191,9 @@ fn goto_file_impl(cx: &mut Context, action: Action) { }; let path = { - let start = { - let cursor_pos = primary.cursor(text.slice(..)); + let cursor_pos = primary.cursor(text.slice(..)); + let start = { let pre_cursor_pos = cursor_pos.saturating_sub(1); let post_cursor_pos = cursor_pos.saturating_add(1); @@ -1206,18 +1206,15 @@ fn goto_file_impl(cx: &mut Context, action: Action) { } }; - let head = start + let prefix_len = start .clone() .reversed() .take_while(is_valid_path_char) - .collect::() - .chars() - .rev() - .collect::(); - - let tail = start.take_while(is_valid_path_char).collect::(); + .count(); - format!("{}{}", head, tail) + let postfix_len = start.take_while(is_valid_path_char).count(); + let path = text.slice((cursor_pos - prefix_len)..(cursor_pos + postfix_len)); + Cow::Borrowed(path.as_str().unwrap()) }; log::debug!("Goto file path: {}", path); From 63218c3caa950ec699b32f208427703a9e9846c0 Mon Sep 17 00:00:00 2001 From: TornaxO7 Date: Thu, 11 Jan 2024 18:31:23 +0100 Subject: [PATCH 10/20] goto-file: remove one nesting --- helix-term/src/commands.rs | 47 ++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 9a8479f1184e..86b8fecb60d2 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1190,32 +1190,35 @@ fn goto_file_impl(cx: &mut Context, action: Action) { valid_chars.contains(c) || c.is_alphabetic() }; - let path = { - let cursor_pos = primary.cursor(text.slice(..)); + let cursor_pos = primary.cursor(text.slice(..)); - let start = { - let pre_cursor_pos = cursor_pos.saturating_sub(1); - let post_cursor_pos = cursor_pos.saturating_add(1); + let start = { + let pre_cursor_pos = cursor_pos.saturating_sub(1); + let post_cursor_pos = cursor_pos.saturating_add(1); - if is_valid_path_char(&text.char(cursor_pos)) { - text.chars_at(cursor_pos) - } else if is_valid_path_char(&text.char(pre_cursor_pos)) { - text.chars_at(pre_cursor_pos) - } else { - text.chars_at(post_cursor_pos) - } - }; + if is_valid_path_char(&text.char(cursor_pos)) { + text.chars_at(cursor_pos) + } else if is_valid_path_char(&text.char(pre_cursor_pos)) { + text.chars_at(pre_cursor_pos) + } else { + text.chars_at(post_cursor_pos) + } + }; - let prefix_len = start - .clone() - .reversed() - .take_while(is_valid_path_char) - .count(); + let prefix_len = start + .clone() + .reversed() + .take_while(is_valid_path_char) + .count(); + + let postfix_len = start.take_while(is_valid_path_char).count(); + + let path = Cow::Borrowed( + text.slice((cursor_pos - prefix_len)..(cursor_pos + postfix_len)) + .as_str() + .unwrap(), + ); - let postfix_len = start.take_while(is_valid_path_char).count(); - let path = text.slice((cursor_pos - prefix_len)..(cursor_pos + postfix_len)); - Cow::Borrowed(path.as_str().unwrap()) - }; log::debug!("Goto file path: {}", path); match shellexpand::full(&path) { From 1b9f5c4cdafc8977920101ec1068f4a933867de1 Mon Sep 17 00:00:00 2001 From: TornaxO7 Date: Thu, 11 Jan 2024 19:03:58 +0100 Subject: [PATCH 11/20] goto-file: fix ci --- helix-term/src/commands.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 86b8fecb60d2..8a7e5776cd7b 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1190,35 +1190,37 @@ fn goto_file_impl(cx: &mut Context, action: Action) { valid_chars.contains(c) || c.is_alphabetic() }; - let cursor_pos = primary.cursor(text.slice(..)); - - let start = { + let start_pos = { + let cursor_pos = primary.cursor(text.slice(..)); let pre_cursor_pos = cursor_pos.saturating_sub(1); let post_cursor_pos = cursor_pos.saturating_add(1); if is_valid_path_char(&text.char(cursor_pos)) { - text.chars_at(cursor_pos) + cursor_pos } else if is_valid_path_char(&text.char(pre_cursor_pos)) { - text.chars_at(pre_cursor_pos) + pre_cursor_pos } else { - text.chars_at(post_cursor_pos) + post_cursor_pos } }; - let prefix_len = start + let prefix_len = text + .chars_at(start_pos) .clone() .reversed() .take_while(is_valid_path_char) .count(); - let postfix_len = start.take_while(is_valid_path_char).count(); + let postfix_len = text + .chars_at(start_pos) + .take_while(is_valid_path_char) + .count(); let path = Cow::Borrowed( - text.slice((cursor_pos - prefix_len)..(cursor_pos + postfix_len)) + text.slice((start_pos - prefix_len)..(start_pos + postfix_len)) .as_str() .unwrap(), ); - log::debug!("Goto file path: {}", path); match shellexpand::full(&path) { From 583d9aac7d1a59f6b9fc029aefef0fa88a263f5e Mon Sep 17 00:00:00 2001 From: TornaxO7 Date: Sat, 24 Feb 2024 19:23:52 +0100 Subject: [PATCH 12/20] improve code format Co-authored-by: Michael Davis --- helix-term/src/commands.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 8a7e5776cd7b..6aa5cae86bf9 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1216,11 +1216,9 @@ fn goto_file_impl(cx: &mut Context, action: Action) { .take_while(is_valid_path_char) .count(); - let path = Cow::Borrowed( - text.slice((start_pos - prefix_len)..(start_pos + postfix_len)) - .as_str() - .unwrap(), - ); + let path: Cow = text + .slice((start_pos - prefix_len)..(start_pos + postfix_len)) + .into(); log::debug!("Goto file path: {}", path); match shellexpand::full(&path) { From f8063bb7c4ee080d7df2293ef8aa669a481e880f Mon Sep 17 00:00:00 2001 From: TornaxO7 Date: Sat, 24 Feb 2024 19:36:14 +0100 Subject: [PATCH 13/20] removing `shellexpand` dependency --- helix-term/Cargo.toml | 5 +---- helix-term/src/commands.rs | 7 ++++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/helix-term/Cargo.toml b/helix-term/Cargo.toml index bfc06886bf8d..1e21ec1610cd 100644 --- a/helix-term/Cargo.toml +++ b/helix-term/Cargo.toml @@ -71,10 +71,7 @@ serde = { version = "1.0", features = ["derive"] } grep-regex = "0.1.12" grep-searcher = "0.1.13" -# expand env-variables in paths -shellexpand = "3.1" - -[target.'cfg(not(windows))'.dependencies] # https://github.com/vorner/signal-hook/issues/100 +[target.'cfg(not(windows))'.dependencies] # https://github.com/vorner/signal-hook/issues/100 signal-hook-tokio = { version = "0.3", features = ["futures-v0_3"] } libc = "0.2.153" diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 783c7bb53837..339b9d837568 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -3,6 +3,7 @@ pub(crate) mod lsp; pub(crate) mod typed; pub use dap::*; +use helix_stdx::path::expand_tilde; use helix_vcs::Hunk; pub use lsp::*; use tui::widgets::Row; @@ -1222,9 +1223,9 @@ fn goto_file_impl(cx: &mut Context, action: Action) { .into(); log::debug!("Goto file path: {}", path); - match shellexpand::full(&path) { - Ok(path) => paths.push(path.to_string()), - Err(e) => cx.editor.set_error(format!("{}", e)), + match expand_tilde(PathBuf::from(path.as_ref())).to_str() { + Some(path) => paths.push(path.to_string()), + None => cx.editor.set_error("Couldn't get string out of path."), }; } From 7fbcbc0759125e75dec29679689951b71d31871c Mon Sep 17 00:00:00 2001 From: TornaxO7 Date: Sat, 24 Feb 2024 19:38:11 +0100 Subject: [PATCH 14/20] reducing nested blocks --- helix-term/src/commands.rs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 339b9d837568..6d63ab70eae0 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1192,18 +1192,15 @@ fn goto_file_impl(cx: &mut Context, action: Action) { valid_chars.contains(c) || c.is_alphabetic() }; - let start_pos = { - let cursor_pos = primary.cursor(text.slice(..)); - let pre_cursor_pos = cursor_pos.saturating_sub(1); - let post_cursor_pos = cursor_pos.saturating_add(1); - - if is_valid_path_char(&text.char(cursor_pos)) { - cursor_pos - } else if is_valid_path_char(&text.char(pre_cursor_pos)) { - pre_cursor_pos - } else { - post_cursor_pos - } + let cursor_pos = primary.cursor(text.slice(..)); + let pre_cursor_pos = cursor_pos.saturating_sub(1); + let post_cursor_pos = cursor_pos.saturating_add(1); + let start_pos = if is_valid_path_char(&text.char(cursor_pos)) { + cursor_pos + } else if is_valid_path_char(&text.char(pre_cursor_pos)) { + pre_cursor_pos + } else { + post_cursor_pos }; let prefix_len = text From b7bd427a2b4474b44665c478bb4c07b1544e5d77 Mon Sep 17 00:00:00 2001 From: TornaxO7 Date: Sat, 24 Feb 2024 19:43:17 +0100 Subject: [PATCH 15/20] removing unecessary clone --- helix-term/src/commands.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 6d63ab70eae0..6b75c2617c5e 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1205,7 +1205,6 @@ fn goto_file_impl(cx: &mut Context, action: Action) { let prefix_len = text .chars_at(start_pos) - .clone() .reversed() .take_while(is_valid_path_char) .count(); From a5cd316fb9090b9aa98d78e566f2caf67e9cc4f0 Mon Sep 17 00:00:00 2001 From: TornaxO7 Date: Sat, 24 Feb 2024 19:44:17 +0100 Subject: [PATCH 16/20] allow numeric-values in path for goto-file --- helix-term/src/commands.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 6b75c2617c5e..d3607513dfb7 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1189,7 +1189,7 @@ fn goto_file_impl(cx: &mut Context, action: Action) { } else { &['@', '/', '.', '-', '_', '+', '#', '$', '%', '~', '='] }; - valid_chars.contains(c) || c.is_alphabetic() + valid_chars.contains(c) || c.is_alphabetic() || c.is_numeric() }; let cursor_pos = primary.cursor(text.slice(..)); From c5c4c3efd69098f541bfbd85be7c1d923b1c6508 Mon Sep 17 00:00:00 2001 From: TornaxO7 Date: Sat, 24 Feb 2024 19:47:00 +0100 Subject: [PATCH 17/20] add test to allow numeric values in filename for goto-file --- helix-term/tests/test/commands.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/helix-term/tests/test/commands.rs b/helix-term/tests/test/commands.rs index 2d635ba342d1..6dcec9d7e06f 100644 --- a/helix-term/tests/test/commands.rs +++ b/helix-term/tests/test/commands.rs @@ -164,6 +164,17 @@ async fn test_goto_file_impl() -> anyhow::Result<()> { ) .await?; + // allow numeric values in path + test_key_sequence( + &mut AppBuilder::new().with_file(file.path(), None).build()?, + Some("iimport 'one123.js'B;gf"), + Some(&|app| { + assert_eq!(1, match_paths(app, vec!["one123.js"])); + }), + false, + ) + .await?; + Ok(()) } From 6cce366d1b761524a135fab8a9182c37fc2c7e9f Mon Sep 17 00:00:00 2001 From: TornaxO7 Date: Tue, 27 Feb 2024 14:50:36 +0100 Subject: [PATCH 18/20] use `cfg` attribute instead of macro --- helix-term/src/commands.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 9393b78445ce..1787b8725041 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1186,14 +1186,14 @@ fn goto_file_impl(cx: &mut Context, action: Action) { paths.clear(); let is_valid_path_char = |c: &char| { - let valid_chars: &[char] = if cfg!(target_os = "windows") { - &[ - '@', '/', '\\', '.', '-', '_', '+', '#', '$', '%', '{', '}', '[', ']', ':', - '!', '~', '=', - ] - } else { - &['@', '/', '.', '-', '_', '+', '#', '$', '%', '~', '='] - }; + #[cfg(target_os = "windows")] + let valid_chars: &[char] = &[ + '@', '/', '\\', '.', '-', '_', '+', '#', '$', '%', '{', '}', '[', ']', ':', '!', + '~', '=', + ]; + #[cfg(not(target_os = "windows"))] + let valid_chars: &[char] = &['@', '/', '.', '-', '_', '+', '#', '$', '%', '~', '=']; + valid_chars.contains(c) || c.is_alphabetic() || c.is_numeric() }; From 51dfd0a526548d2f39ae0c7f464a2ef80e475d4f Mon Sep 17 00:00:00 2001 From: TornaxO7 Date: Tue, 27 Feb 2024 14:55:37 +0100 Subject: [PATCH 19/20] removing saturating add --- helix-term/src/commands.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 1787b8725041..c2e9cd226f45 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1199,7 +1199,7 @@ fn goto_file_impl(cx: &mut Context, action: Action) { let cursor_pos = primary.cursor(text.slice(..)); let pre_cursor_pos = cursor_pos.saturating_sub(1); - let post_cursor_pos = cursor_pos.saturating_add(1); + let post_cursor_pos = cursor_pos + 1; let start_pos = if is_valid_path_char(&text.char(cursor_pos)) { cursor_pos } else if is_valid_path_char(&text.char(pre_cursor_pos)) { From 366d792a91d8b0aa8837ecf3167ae30cef69ad19 Mon Sep 17 00:00:00 2001 From: TornaxO7 Date: Sat, 6 Apr 2024 21:22:54 +0200 Subject: [PATCH 20/20] goto-file: adjust valid chars --- helix-term/src/commands.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 46234fd45052..99e7608fcb5a 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1203,12 +1203,12 @@ fn goto_file_impl(cx: &mut Context, action: Action) { let is_valid_path_char = |c: &char| { #[cfg(target_os = "windows")] - let valid_chars: &[char] = &[ + let valid_chars = &[ '@', '/', '\\', '.', '-', '_', '+', '#', '$', '%', '{', '}', '[', ']', ':', '!', '~', '=', ]; #[cfg(not(target_os = "windows"))] - let valid_chars: &[char] = &['@', '/', '.', '-', '_', '+', '#', '$', '%', '~', '=']; + let valid_chars = &['@', '/', '.', '-', '_', '+', '#', '$', '%', '~', '=', ':']; valid_chars.contains(c) || c.is_alphabetic() || c.is_numeric() };