Skip to content

Commit

Permalink
feat: use Utf8PathBuf struct instead of checking for end of file
Browse files Browse the repository at this point in the history
  • Loading branch information
nik-rev committed Dec 17, 2024
1 parent cefa10d commit b45d3eb
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions helix-term/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ use helix_view::Editor;

use std::{error::Error, path::PathBuf};

struct Utf8PathBuf {
path: String,
is_dir: bool,
}

impl AsRef<str> for Utf8PathBuf {
fn as_ref(&self) -> &str {
&self.path
}
}

pub fn prompt(
cx: &mut crate::commands::Context,
prompt: std::borrow::Cow<'static, str>,
Expand Down Expand Up @@ -267,6 +278,7 @@ pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> FilePi

pub mod completers {
use crate::ui::prompt::Completion;
use crate::ui::Utf8PathBuf;
use helix_core::fuzzy::fuzzy_match;
use helix_core::syntax::LanguageServerFeature;
use helix_view::document::SCRATCH_BUFFER_NAME;
Expand Down Expand Up @@ -483,7 +495,7 @@ pub mod completers {
return None;
}

//let is_dir = entry.file_type().map_or(false, |entry| entry.is_dir());
let is_dir = entry.file_type().map_or(false, |entry| entry.is_dir());

let path = entry.path();
let mut path = if is_tilde {
Expand All @@ -502,18 +514,18 @@ pub mod completers {
}

let path = path.into_os_string().into_string().ok()?;
Some(Cow::from(path))
Some(Utf8PathBuf { path, is_dir })
})
}) // TODO: unwrap or skip
.filter(|path| !path.is_empty());
.filter(|path| !path.path.is_empty());

let directory_color = editor.theme.get("ui.text.directory");

let style_from_file = |file: Cow<'static, str>| {
if file.ends_with(std::path::MAIN_SEPARATOR) {
Span::styled(file, directory_color)
let style_from_file = |file: Utf8PathBuf| {
if file.is_dir {
Span::styled(file.path, directory_color)
} else {
Span::raw(file)
Span::raw(file.path)
}
};

Expand Down

0 comments on commit b45d3eb

Please sign in to comment.