Skip to content

Commit

Permalink
use get_normalized_path before stripping to relative path
Browse files Browse the repository at this point in the history
  • Loading branch information
jazzfool committed Mar 14, 2023
1 parent c3be3ff commit e0f2c4a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions helix-core/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,19 @@ pub fn get_canonicalized_path(path: &Path) -> std::io::Result<PathBuf> {
}

pub fn get_relative_path(path: &Path) -> PathBuf {
let path = PathBuf::from(path);
let path = if path.is_absolute() {
let cwdir = std::env::current_dir().expect("couldn't determine current directory");
path.strip_prefix(cwdir).unwrap_or(path)
let cwdir = std::env::current_dir()
.map(|path| get_normalized_path(&path))
.expect("couldn't determine current directory");
get_normalized_path(&path)
.strip_prefix(cwdir)
.map(PathBuf::from)
.unwrap_or(path)
} else {
path
};
fold_home_dir(path)
fold_home_dir(&path)
}

/// Returns a truncated filepath where the basepart of the path is reduced to the first
Expand Down

0 comments on commit e0f2c4a

Please sign in to comment.