Skip to content

fix: fixed forced workspace mode enablement #2565

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
70 changes: 56 additions & 14 deletions crates/atuin-client/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,28 @@ pub struct Daemon {
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Search {
/// The list of enabled filter modes, in order of priority.
pub filters: Vec<FilterMode>,
pub filters: EnabledFilterModes,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct EnabledFilterModes(Vec<FilterMode>);

impl EnabledFilterModes {
pub fn specified(&self) -> &[FilterMode] {
&self.0
}

pub fn resolved(&self, legacy_workspaces: bool) -> &[FilterMode] {
if self.0.is_empty() {
if legacy_workspaces {
DEFAULT_LEGACY_WORKSPACE_FILTER_MODES
} else {
DEFAULT_FILTER_MODES
}
} else {
&self.0
}
}
}

impl Default for Preview {
Expand Down Expand Up @@ -409,17 +430,33 @@ impl Default for Daemon {
impl Default for Search {
fn default() -> Self {
Self {
filters: vec![
FilterMode::Global,
FilterMode::Host,
FilterMode::Session,
FilterMode::Workspace,
FilterMode::Directory,
],
filters: EnabledFilterModes(vec![]),
}
}
}

const DEFAULT_FILTER_MODES: &[FilterMode] = &[
FilterMode::Global,
FilterMode::Host,
FilterMode::Session,
FilterMode::Workspace,
FilterMode::Directory,
];

const DEFAULT_LEGACY_WORKSPACE_FILTER_MODES: &[FilterMode] = &[
FilterMode::Workspace,
FilterMode::Global,
FilterMode::Host,
FilterMode::Session,
FilterMode::Directory,
];

impl Default for EnabledFilterModes {
fn default() -> Self {
Self(DEFAULT_FILTER_MODES.into())
}
}

// The preview height strategy also takes max_preview_height into account.
#[derive(Clone, Debug, Deserialize, Copy, PartialEq, Eq, ValueEnum, Serialize)]
pub enum PreviewStrategy {
Expand Down Expand Up @@ -712,12 +749,21 @@ impl Settings {
}

pub fn default_filter_mode(&self) -> FilterMode {
if self.search.filters.specified().is_empty() && self.workspaces {
return FilterMode::Workspace;
}

let filters = self.filter_modes();
self.filter_mode
.filter(|x| self.search.filters.contains(x))
.or(self.search.filters.first().copied())
.filter(|x| filters.contains(x))
.or(filters.first().copied())
.unwrap_or(FilterMode::Global)
}

pub fn filter_modes(&self) -> &[FilterMode] {
self.search.filters.resolved(self.workspaces)
}

#[cfg(not(feature = "check-update"))]
pub async fn needs_update(&self) -> Option<Version> {
None
Expand Down Expand Up @@ -788,10 +834,6 @@ impl Settings {
.set_default("daemon.socket_path", socket_path.to_str())?
.set_default("daemon.systemd_socket", false)?
.set_default("daemon.tcp_port", 8889)?
.set_default(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about this change.
I noticed duplicate defaults for many parameters here and didn't understand the purpose.

"search.filters",
vec!["global", "host", "session", "workspace", "directory"],
)?
.set_default("theme.name", "default")?
.set_default("theme.debug", None::<bool>)?
.set_default(
Expand Down
11 changes: 5 additions & 6 deletions crates/atuin/src/command/client/search/engines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@ pub struct SearchState {

impl SearchState {
pub(crate) fn rotate_filter_mode(&mut self, settings: &Settings, offset: isize) {
let mut i = settings
.search
.filters
let filters = settings.filter_modes();
let mut i = filters
.iter()
.position(|&m| m == self.filter_mode)
.unwrap_or_default();
for _ in 0..settings.search.filters.len() {
i = (i.wrapping_add_signed(offset)) % settings.search.filters.len();
let mode = settings.search.filters[i];
for _ in 0..filters.len() {
i = (i.wrapping_add_signed(offset)) % filters.len();
let mode = filters[i];
if self.filter_mode_available(mode, settings) {
self.filter_mode = mode;
break;
Expand Down