diff options
author | Canop <cano.petrole@gmail.com> | 2022-07-10 22:28:15 +0200 |
---|---|---|
committer | Canop <cano.petrole@gmail.com> | 2022-07-10 22:29:23 +0200 |
commit | 94ef5f6ed4376df0d1b96b2ba38e8f5b2ca70ed9 (patch) | |
tree | d7056f2b4eb07aa4b2d99c0a832b560da90e766e /src/app | |
parent | d4751c863011bf2583b07942363df3f70db37d97 (diff) |
allow :focus based verbs to take a pattern
This allows verb definitions such as the following ones:
```Hjson
{
invocation: "gos"
execution: ":focus"
}
{
invocation: "go {path}"
execution: ":focus {path}"
}
{
invocation: "goroot"
execution: ":focus /"
}
{
invocation: "gotar {path}"
execution: ":focus {path}/target"
}
```
Fix #389
Diffstat (limited to 'src/app')
-rw-r--r-- | src/app/panel_state.rs | 19 | ||||
-rw-r--r-- | src/app/selection.rs | 13 |
2 files changed, 26 insertions, 6 deletions
diff --git a/src/app/panel_state.rs b/src/app/panel_state.rs index ebe6038..f84f697 100644 --- a/src/app/panel_state.rs +++ b/src/app/panel_state.rs @@ -476,7 +476,14 @@ pub trait PanelState { } let res = match &verb.execution { VerbExecution::Internal(internal_exec) => { - self.on_internal(w, internal_exec, invocation, trigger_type, app_state, cc) + self.on_internal( + w, + internal_exec, + invocation, + trigger_type, + app_state, + cc, + ) } VerbExecution::External(external) => { self.execute_external(w, verb, external, invocation, app_state, cc) @@ -522,9 +529,9 @@ pub trait PanelState { sel_info, app_state, if let Some(inv) = invocation { - &inv.args + inv.args.as_ref() } else { - &None + None }, ); external_execution.to_cmd_result(w, exec_builder, cc.app.con) @@ -551,9 +558,9 @@ pub trait PanelState { sel_info, app_state, if let Some(inv) = invocation { - &inv.args + inv.args.as_ref() } else { - &None + None }, ); // TODO what follows is dangerous: if an inserted group value contains the separator, @@ -617,7 +624,7 @@ pub trait PanelState { w, verb, Some(invocation), - TriggerType::Input, + TriggerType::Input(verb), app_state, cc, ) diff --git a/src/app/selection.rs b/src/app/selection.rs index e3a84f8..2fb56b7 100644 --- a/src/app/selection.rs +++ b/src/app/selection.rs @@ -96,6 +96,16 @@ impl Selection<'_> { } impl<'a> SelInfo<'a> { + pub fn from_path(path: &'a Path) -> Self { + Self::One( + Selection { + stype: SelectionType::from(path), + line: 0, + path, + is_exe: false, // OK, I don't know + } + ) + } pub fn count_paths(&self) -> usize { match self { SelInfo::None => 0, @@ -124,6 +134,9 @@ impl<'a> SelInfo<'a> { _ => None, } } + pub fn one_path(self) -> Option<&'a Path> { + self.one_sel().map(|sel| sel.path) + } pub fn extension(&self) -> Option<&str> { match self { SelInfo::None => None, |