Skip to content

Commit

Permalink
make buffer picker more clear
Browse files Browse the repository at this point in the history
  • Loading branch information
Kl4rry committed Jul 4, 2024
1 parent 74e4e52 commit 01b3d5b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
11 changes: 9 additions & 2 deletions crates/ferrite-core/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{

use anyhow::Result;
use ferrite_cli::Args;
use ferrite_utility::line_ending;
use ferrite_utility::{line_ending, trim::trim_path};
use slab::Slab;
use subprocess::{Exec, Redirection};

Expand Down Expand Up @@ -879,7 +879,14 @@ impl Engine {
.map(|(id, buffer)| BufferItem {
id,
dirty: buffer.is_dirty(),
name: buffer.name().to_string(),
name: {
let current_dir = env::current_dir().unwrap_or_else(|_| PathBuf::new());
let current_dir = current_dir.to_string_lossy();
buffer
.file()
.map(|path| trim_path(&current_dir, path))
.unwrap_or_else(|| buffer.name().to_string())
},
})
.collect();

Expand Down
8 changes: 1 addition & 7 deletions crates/ferrite-core/src/search_buffer/file_daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::{
};

use cb::select;
use ferrite_utility::trim::trim_path;
use ignore::gitignore::{Gitignore, GitignoreBuilder};
use notify::{RecursiveMode, Watcher};
use rayon::prelude::*;
Expand Down Expand Up @@ -41,13 +42,6 @@ fn is_text_file(path: impl AsRef<Path>) -> bool {
content_type.is_text()
}

fn trim_path(start: &str, path: &Path) -> String {
path.to_string_lossy()
.trim_start_matches(start)
.trim_start_matches(std::path::MAIN_SEPARATOR)
.to_string()
}

#[repr(transparent)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct LexicallySortedString(pub String);
Expand Down
1 change: 1 addition & 0 deletions crates/ferrite-utility/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pub mod chars;
pub mod graphemes;
pub mod line_ending;
pub mod point;
pub mod trim;
13 changes: 13 additions & 0 deletions crates/ferrite-utility/src/trim.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use std::path::Path;

pub fn trim_path(start: &str, path: &Path) -> String {
let path_str = path.to_string_lossy();
let without_start = path_str.trim_start_matches(start);
if without_start < start {
without_start
.trim_start_matches(std::path::MAIN_SEPARATOR)
.to_string()
} else {
without_start.to_string()
}
}

0 comments on commit 01b3d5b

Please sign in to comment.