summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenys Séguret <cano.petrole@gmail.com>2024-03-09 08:57:11 +0100
committerGitHub <noreply@github.com>2024-03-09 08:57:11 +0100
commit36abe9cb3fd8ba55b880ce68d9f22cbe3c0a8d65 (patch)
treeaf8e57e8f80ccda0bd1daeff3c9bb55df6441543
parent53d193cd9a15f4750e757e6901eab80e73264c6d (diff)
Stage all directories (#850)
Fix #844
-rw-r--r--src/browser/browser_state.rs33
-rw-r--r--src/tree_build/builder.rs4
-rw-r--r--src/verb/internal.rs1
-rw-r--r--src/verb/verb_store.rs1
-rw-r--r--website/docs/conf_verbs.md1
5 files changed, 34 insertions, 6 deletions
diff --git a/src/browser/browser_state.rs b/src/browser/browser_state.rs
index e84788e..bec8808 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 5001902..a153ae0 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 d15c774..744bcd9 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 ce2f5ad..a599c8f 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 cad0b74..c4f2c04 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 | <kbd>+</kbd> | - | add selection to staging area
+:stage_all_directories | - | - | add all directories verifying the pattern to the staging area
:stage_all_files | <kbd>ctrl</kbd><kbd>a</kbd> | - | 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