summaryrefslogtreecommitdiffstats
path: root/src/command
diff options
context:
space:
mode:
authorCanop <cano.petrole@gmail.com>2020-07-26 18:07:24 +0200
committerCanop <cano.petrole@gmail.com>2020-07-26 18:07:24 +0200
commitb2f489e9c731a62dd1a63b4b82b43509ef58d602 (patch)
tree30cbcd5a2637a12af202c6a7a3ecb5e58fc37616 /src/command
parent53cc8f0fa652c7e04d04490c0d6cfd84006c58ed (diff)
{line} in a verb execution pattern refers to the line number
This makes it possible to open files directly on the line which was selected in the preview
Diffstat (limited to 'src/command')
-rw-r--r--src/command/completion.rs14
-rw-r--r--src/command/event.rs13
2 files changed, 13 insertions, 14 deletions
diff --git a/src/command/completion.rs b/src/command/completion.rs
index 0486c4c..d5ec759 100644
--- a/src/command/completion.rs
+++ b/src/command/completion.rs
@@ -4,7 +4,7 @@ use {
crate::{
app::{
AppContext,
- AppState,
+ Selection,
},
path,
path_anchor::PathAnchor,
@@ -105,12 +105,12 @@ impl Completions {
anchor: PathAnchor,
arg: &str,
_con: &AppContext,
- state: &dyn AppState,
+ sel: Selection<'_>,
) -> io::Result<Self> {
let c = regex!(r"^(.*?)([^/]*)$").captures(arg).unwrap();
let parent_part = &c[1];
let child_part = &c[2];
- let parent = path::path_from(state.selected_path(), anchor, parent_part);
+ let parent = path::path_from(sel.path, anchor, parent_part);
if !parent.exists() {
debug!("no path completion possible because {:?} doesn't exist", &parent);
return Ok(Self::None);
@@ -138,7 +138,7 @@ impl Completions {
verb_name: &str,
arg: &str,
con: &AppContext,
- state: &dyn AppState,
+ sel: Selection<'_>,
) -> Self {
// in the future we might offer completion of other types
// of arguments, maybe user supplied, but there's no use case
@@ -150,7 +150,7 @@ impl Completions {
PrefixSearchResult::Match(_, verb) => verb.get_arg_anchor(),
_ => PathAnchor::Unspecified,
};
- match Self::for_path(anchor, arg, con, state) {
+ match Self::for_path(anchor, arg, con, sel) {
Ok(c) => c,
Err(e) => {
warn!("Error while trying to complete path: {:?}", e);
@@ -163,7 +163,7 @@ impl Completions {
pub fn for_input(
parts: &CommandParts,
con: &AppContext,
- state: &dyn AppState,
+ sel: Selection<'_>,
) -> Self {
match &parts.verb_invocation {
Some(invocation) if !invocation.is_empty() => {
@@ -174,7 +174,7 @@ impl Completions {
}
Some(args) if !args.is_empty() => {
// looking into arg completion
- Self::for_arg(&invocation.name, args, con, state)
+ Self::for_arg(&invocation.name, args, con, sel)
}
_ => {
// nothing possible
diff --git a/src/command/event.rs b/src/command/event.rs
index 7a5bbbe..f7b2a54 100644
--- a/src/command/event.rs
+++ b/src/command/event.rs
@@ -3,7 +3,7 @@ use {
crate::{
app::{
AppContext,
- AppState,
+ Selection,
},
display::W,
errors::ProgramError,
@@ -62,9 +62,9 @@ impl PanelInput {
w: &mut W,
event: Event,
con: &AppContext,
- state: &dyn AppState,
+ sel: Selection<'_>,
) -> Result<Command, ProgramError> {
- let cmd = self.get_command(event, con, state);
+ let cmd = self.get_command(event, con, sel);
self.input_field.display_on(w)?;
Ok(cmd)
}
@@ -103,7 +103,7 @@ impl PanelInput {
&mut self,
event: Event,
con: &AppContext,
- state: &dyn AppState,
+ sel: Selection<'_>,
) -> Command {
match event {
Event::Click(x, y, ..) => {
@@ -151,7 +151,7 @@ impl PanelInput {
} else {
&parts
};
- let completions = Completions::for_input(completable_parts, con, state);
+ let completions = Completions::for_input(completable_parts, con, sel);
let added = match completions {
Completions::None => {
debug!("nothing to complete!"); // where to tell this ? input field or status ?
@@ -200,14 +200,13 @@ impl PanelInput {
}
// we now check if the key is the trigger key of one of the verbs
- let selection_type = state.selection_type();
for (index, verb) in con.verb_store.verbs.iter().enumerate() {
for verb_key in &verb.keys {
if *verb_key == key {
if self.handle_input_related_verb(verb, con) {
return Command::from_raw(self.input_field.get_content(), false);
}
- if selection_type.respects(verb.selection_condition) {
+ if sel.stype.respects(verb.selection_condition) {
return Command::VerbTrigger {
index,
input_invocation: parts.verb_invocation,