Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve goto_file_impl #9065

Merged
merged 23 commits into from
Apr 6, 2024
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
eab5cbd
adding `shellexpand` and extend `surround_chars`
TornaxO7 Dec 12, 2023
0fdbc66
goto-file-path: adding test with ending character
TornaxO7 Dec 12, 2023
5f83d91
reformat code
TornaxO7 Dec 12, 2023
df34a6a
improving char collection for path
TornaxO7 Dec 13, 2023
264cd2b
add heuristic if cursor is on invalid char
TornaxO7 Dec 13, 2023
a88c86d
fix test
TornaxO7 Dec 13, 2023
1753c69
make clippy happy
TornaxO7 Dec 13, 2023
0da3262
removing `,` from the accepted file paths
TornaxO7 Dec 13, 2023
014a152
goto-file: improve head and tail detection
TornaxO7 Jan 11, 2024
63218c3
goto-file: remove one nesting
TornaxO7 Jan 11, 2024
1b9f5c4
goto-file: fix ci
TornaxO7 Jan 11, 2024
583d9aa
improve code format
TornaxO7 Feb 24, 2024
9bbccc5
Merge branch 'master' into feat/extend-goto-file
TornaxO7 Feb 24, 2024
f8063bb
removing `shellexpand` dependency
TornaxO7 Feb 24, 2024
7fbcbc0
reducing nested blocks
TornaxO7 Feb 24, 2024
b7bd427
removing unecessary clone
TornaxO7 Feb 24, 2024
a5cd316
allow numeric-values in path for goto-file
TornaxO7 Feb 24, 2024
c5c4c3e
add test to allow numeric values in filename for goto-file
TornaxO7 Feb 24, 2024
893c590
Merge branch 'master' of github.com:helix-editor/helix into feat/exte…
TornaxO7 Feb 27, 2024
6cce366
use `cfg` attribute instead of macro
TornaxO7 Feb 27, 2024
51dfd0a
removing saturating add
TornaxO7 Feb 27, 2024
de4fdbe
Merge branch 'master' of github.com:helix-editor/helix into feat/exte…
TornaxO7 Apr 6, 2024
366d792
goto-file: adjust valid chars
TornaxO7 Apr 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add heuristic if cursor is on invalid char
  • Loading branch information
TornaxO7 committed Dec 13, 2023
commit 264cd2b91558d56c32d82d52fb03d759a08c53c2
33 changes: 21 additions & 12 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1191,26 +1191,35 @@ fn goto_file_impl(cx: &mut Context, action: Action) {
};

let path = {
TornaxO7 marked this conversation as resolved.
Show resolved Hide resolved
let cursor = primary.cursor(text.slice(..));
let start = {
the-mikedavis marked this conversation as resolved.
Show resolved Hide resolved
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::<String>()
.chars()
.rev()
.collect::<String>();

TornaxO7 marked this conversation as resolved.
Show resolved Hide resolved
let tail = text
.chars_at(cursor)
.take_while(is_valid_path_char)
.collect::<String>();
let tail = start.take_while(is_valid_path_char).collect::<String>();

format!("{}{}", head, tail)
};
log::debug!("Goto file path: {}", path);

match shellexpand::full(&path) {
TornaxO7 marked this conversation as resolved.
Show resolved Hide resolved
Ok(path) => paths.push(path.to_string()),
Expand Down