summaryrefslogtreecommitdiffstats
path: root/src/command
diff options
context:
space:
mode:
authorCanop <cano.petrole@gmail.com>2021-04-26 21:07:41 +0200
committerCanop <cano.petrole@gmail.com>2021-04-26 21:07:41 +0200
commit679afd0b48c6990413e310e6d4318f7ce94cf76e (patch)
tree6d60e8dfb62d6884e8d21b17d38129ed19c99a1a /src/command
parent1a2014aa856e95176e4ad16497c81ad76ab2b71c (diff)
better check of verb conditions, sequences not allowed on SA
The execution of a verb can have many different side effects affecting the execution of a following one: a verb can (un)stage, change files, change their types, change the focused panel, etc. It's too hard to reason about all those effects, and this can't be expected from the user. So, at least for now, I forbid sequence execution on multiple files.
Diffstat (limited to 'src/command')
-rw-r--r--src/command/completion.rs13
-rw-r--r--src/command/sequence.rs10
2 files changed, 14 insertions, 9 deletions
diff --git a/src/command/completion.rs b/src/command/completion.rs
index 81492e9..d9d8ef1 100644
--- a/src/command/completion.rs
+++ b/src/command/completion.rs
@@ -3,7 +3,6 @@ use {
crate::{
app::{
AppContext,
- SelectionType,
SelInfo,
},
path::{self, PathAnchor},
@@ -85,7 +84,7 @@ impl Completions {
con: &AppContext,
sel_info: SelInfo<'_>,
) -> Self {
- match con.verb_store.search(start, sel_info.common_stype()) {
+ match con.verb_store.search_sel_info(start, &sel_info) {
PrefixSearchResult::NoMatch => Self::None,
PrefixSearchResult::Match(name, _) => {
if start.len() >= name.len() {
@@ -106,10 +105,10 @@ impl Completions {
verb_name: &str,
arg: &str,
path: &Path,
- stype: SelectionType,
+ sel_info: &SelInfo<'_>,
con: &AppContext,
) -> io::Result<Vec<String>> {
- let anchor = match con.verb_store.search(verb_name, Some(stype)) {
+ let anchor = match con.verb_store.search_sel_info(verb_name, sel_info) {
PrefixSearchResult::Match(_, verb) => verb.get_arg_anchor(),
_ => PathAnchor::Unspecified,
};
@@ -152,10 +151,10 @@ impl Completions {
if arg.contains(' ') {
return Self::None;
}
- match sel_info {
+ match &sel_info {
SelInfo::None => Self::None,
SelInfo::One(sel) => {
- match Self::list_for_path(verb_name, arg, sel.path, sel.stype, con) {
+ match Self::list_for_path(verb_name, arg, sel.path, &sel_info, con) {
Ok(list) => Self::from_list(list),
Err(e) => {
warn!("Error while trying to complete path: {:?}", e);
@@ -173,7 +172,7 @@ impl Completions {
verb_name,
arg,
path,
- SelectionType::from(path),
+ &sel_info,
con
).ok()
});
diff --git a/src/command/sequence.rs b/src/command/sequence.rs
index 87ee50e..ae319c7 100644
--- a/src/command/sequence.rs
+++ b/src/command/sequence.rs
@@ -6,7 +6,7 @@ use {
crate::{
app::AppContext,
errors::ProgramError,
- verb::PrefixSearchResult,
+ verb::*,
},
};
@@ -59,6 +59,12 @@ impl Sequence {
}
Ok(commands)
}
+ pub fn has_selection_group(&self) -> bool {
+ str_has_selection_group(&self.raw)
+ }
+ pub fn has_other_panel_group(&self) -> bool {
+ str_has_other_panel_group(&self.raw)
+ }
}
/// an input may be made of two parts:
@@ -82,7 +88,7 @@ fn add_commands(
if let Command::VerbInvocate(invocation) = &command {
// we check that the verb exists to avoid running a sequence
// of actions with some missing
- match con.verb_store.search(&invocation.name, None) {
+ match con.verb_store.search_prefix(&invocation.name) {
PrefixSearchResult::NoMatch => {
return Err(ProgramError::UnknownVerb {
name: invocation.name.to_string(),