From 36abe9cb3fd8ba55b880ce68d9f22cbe3c0a8d65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denys=20S=C3=A9guret?= Date: Sat, 9 Mar 2024 08:57:11 +0100 Subject: [PATCH] Stage all directories (#850) Fix #844 --- src/browser/browser_state.rs | 33 ++++++++++++++++++++++++++++----- src/tree_build/builder.rs | 4 +++- src/verb/internal.rs | 1 + src/verb/verb_store.rs | 1 + website/docs/conf_verbs.md | 1 + 5 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/browser/browser_state.rs b/src/browser/browser_state.rs index e84788ef..bec88087 100644 --- a/src/browser/browser_state.rs +++ b/src/browser/browser_state.rs @@ -37,7 +37,10 @@ enum BrowserTask { pattern: InputPattern, total: bool, }, - StageAll(InputPattern), + StageAll { + pattern: InputPattern, + file_type_condition: FileTypeCondition, + }, } impl BrowserState { @@ -215,7 +218,7 @@ impl PanelState for BrowserState { self .pending_task.as_ref().map(|task| match task { BrowserTask::Search{ .. } => "searching", - BrowserTask::StageAll(_) => "staging", + BrowserTask::StageAll{ .. } => "staging", }) } } @@ -526,9 +529,25 @@ impl PanelState for BrowserState { CmdResult::error("No selected line") } } + Internal::stage_all_directories => { + let pattern = self.displayed_tree().options.pattern.clone(); + let file_type_condition = FileTypeCondition::Directory; + self.pending_task = Some(BrowserTask::StageAll{pattern, file_type_condition}); + if cc.app.stage_panel.is_none() { + let stage_options = self.tree.options.without_pattern(); + CmdResult::NewPanel { + state: Box::new(StageState::new(app_state, stage_options, con)), + purpose: PanelPurpose::None, + direction: HDir::Right, + } + } else { + CmdResult::Keep + } + } Internal::stage_all_files => { let pattern = self.displayed_tree().options.pattern.clone(); - self.pending_task = Some(BrowserTask::StageAll(pattern)); + let file_type_condition = FileTypeCondition::File; + self.pending_task = Some(BrowserTask::StageAll{pattern, file_type_condition}); if cc.app.stage_panel.is_none() { let stage_options = self.tree.options.without_pattern(); CmdResult::NewPanel { @@ -684,7 +703,8 @@ impl PanelState for BrowserState { self.filtered_tree = Some(ft); } } - BrowserTask::StageAll(pattern) => { + BrowserTask::StageAll { pattern, file_type_condition } => { + info!("stage all pattern: {:?}", pattern); let tree = self.displayed_tree(); let root = tree.root().clone(); let mut options = tree.options.clone(); @@ -697,7 +717,10 @@ impl PanelState for BrowserState { time!(builder.build_paths( total_search, dam, - |line| line.file_type.is_file() || line.file_type.is_symlink(), + |line| { + info!("??staging {:?}", &line.path); + file_type_condition.accepts_path(&line.path) + } )) })?; for path in paths.drain(..) { diff --git a/src/tree_build/builder.rs b/src/tree_build/builder.rs index 50019024..a153ae08 100644 --- a/src/tree_build/builder.rs +++ b/src/tree_build/builder.rs @@ -499,7 +499,9 @@ impl<'c> TreeBuilder<'c> { .map(|mut blines_ids| { blines_ids .drain(..) - .filter(|&bid| filter(&self.blines[bid])) + .filter(|&bid| { + self.blines[bid].direct_match && filter(&self.blines[bid]) + }) .map(|id| self.blines[id].path.clone()) .collect() }) diff --git a/src/verb/internal.rs b/src/verb/internal.rs index d15c7744..744bcd9e 100644 --- a/src/verb/internal.rs +++ b/src/verb/internal.rs @@ -125,6 +125,7 @@ Internals! { sort_by_type_dirs_first: "sort by type, dirs first" false, sort_by_type_dirs_last: "sort by type, dirs last" false, stage: "add selection to staging area" true, + stage_all_directories: "stage all matching directories" true, stage_all_files: "stage all matching files" true, start_end_panel: "either open or close an additional panel" true, toggle_counts: "toggle showing number of files in directories" false, diff --git a/src/verb/verb_store.rs b/src/verb/verb_store.rs index ce2f5ad1..a599c8f7 100644 --- a/src/verb/verb_store.rs +++ b/src/verb/verb_store.rs @@ -271,6 +271,7 @@ impl VerbStore { .with_key(key!('+')); self.add_internal(unstage) .with_key(key!('-')); + self.add_internal(stage_all_directories); self.add_internal(stage_all_files) .with_key(key!(ctrl-a)); self.add_internal(toggle_stage) diff --git a/website/docs/conf_verbs.md b/website/docs/conf_verbs.md index cad0b74a..c4f2c04b 100644 --- a/website/docs/conf_verbs.md +++ b/website/docs/conf_verbs.md @@ -440,6 +440,7 @@ invocation | default key | default shortcut | behavior / details :sort_by_type_dirs_first | - | - | sort by type, dirs first :sort_by_type_dirs_last | - | - | sort by type, dirs last :stage | + | - | add selection to staging area +:stage_all_directories | - | - | add all directories verifying the pattern to the staging area :stage_all_files | ctrla | - | add all files verifying the pattern to the staging area :start_end_panel | - | - | either open or close an additional panel :toggle_counts | - | - | toggle display of total counts of files per directory