Skip to content

Commit

Permalink
add opt-in
Browse files Browse the repository at this point in the history
  • Loading branch information
ellie committed Apr 2, 2024
1 parent 4ddc7d9 commit d4ae445
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 2 additions & 0 deletions atuin-client/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ pub struct Settings {
pub network_timeout: u64,
pub local_timeout: f64,
pub enter_accept: bool,
pub smart_sort: bool,

#[serde(default)]
pub stats: Stats,
Expand Down Expand Up @@ -631,6 +632,7 @@ impl Settings {
.set_default("keymap_mode", "emacs")?
.set_default("keymap_mode_shell", "auto")?
.set_default("keymap_cursor", HashMap::<String, String>::new())?
.set_default("smart_sort", false)?
.set_default(
"prefers_reduced_motion",
std::env::var("NO_MOTION")
Expand Down
18 changes: 12 additions & 6 deletions atuin/src/command/client/search/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,21 @@ struct StyleState {
}

impl State {
async fn query_results(&mut self, db: &mut dyn Database) -> Result<Vec<History>> {
async fn query_results(
&mut self,
db: &mut dyn Database,
smart_sort: bool,
) -> Result<Vec<History>> {
let results = self.engine.query(&self.search, db).await?;

self.results_state.select(0);
self.results_len = results.len();

let results = sort::sort(self.search.input.as_str(), results);

Ok(results)
if smart_sort {
Ok(sort::sort(self.search.input.as_str(), results))
} else {
Ok(results)
}
}

fn handle_input<W>(
Expand Down Expand Up @@ -1006,7 +1012,7 @@ pub async fn history(

app.initialize_keymap_cursor(settings);

let mut results = app.query_results(&mut db).await?;
let mut results = app.query_results(&mut db, settings.smart_sort).await?;

let mut stats: Option<HistoryStats> = None;
let accept;
Expand Down Expand Up @@ -1067,7 +1073,7 @@ pub async fn history(
|| initial_filter_mode != app.search.filter_mode
|| initial_search_mode != app.search_mode
{
results = app.query_results(&mut db).await?;
results = app.query_results(&mut db, settings.smart_sort).await?;
}

stats = if app.tab_index == 0 {
Expand Down

0 comments on commit d4ae445

Please sign in to comment.