Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

search_again internal #909

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 23 additions & 17 deletions src/app/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,29 @@ impl App {
.refresh_input_status(app_state, &app_cmd_context);
}
}
Internal::search_again => {
if let Some(raw_pattern) = &self.panel().last_raw_pattern {
let sequence = Sequence::new_single(raw_pattern.clone());
self.tx_seqs.send(sequence).unwrap();
}
}
Internal::set_syntax_theme => {
let arg = cmd.as_verb_invocation().and_then(|vi| vi.args.as_ref());
match arg {
Some(arg) => match SyntaxTheme::from_str(arg) {
Ok(theme) => {
con.syntax_theme = Some(theme);
self.update_preview(con, true);
}
Err(e) => {
error = Some(e.to_string());
}
},
None => {
error = Some("no theme provided".to_string());
}
}
}
Internal::toggle_second_tree => {
let panels_count = self.panels.len().get();
let trees_count = self
Expand Down Expand Up @@ -485,23 +508,6 @@ impl App {
}
}
}
Internal::set_syntax_theme => {
let arg = cmd.as_verb_invocation().and_then(|vi| vi.args.as_ref());
match arg {
Some(arg) => match SyntaxTheme::from_str(arg) {
Ok(theme) => {
con.syntax_theme = Some(theme);
self.update_preview(con, true);
}
Err(e) => {
error = Some(e.to_string());
}
},
None => {
error = Some("no theme provided".to_string());
}
}
}
_ => {
info!("unhandled propagated internal. cmd={:?}", &cmd);
}
Expand Down
15 changes: 15 additions & 0 deletions src/app/panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub struct Panel {
status: Status,
pub purpose: PanelPurpose,
pub input: PanelInput,
pub last_raw_pattern: Option<String>,
}

impl Panel {
Expand All @@ -51,6 +52,7 @@ impl Panel {
status,
purpose: PanelPurpose::None,
input,
last_raw_pattern: None,
}
}

Expand All @@ -71,6 +73,9 @@ impl Panel {
app_state: &mut AppState,
app_cmd_context: &'c AppCmdContext<'c>,
) -> Result<CmdResult, ProgramError> {
if let Command::PatternEdit { raw, .. } = cmd {
self.last_raw_pattern = Some(raw.clone());
}
let state_idx = self.states.len() - 1;
let cc = CmdContext {
cmd,
Expand Down Expand Up @@ -275,4 +280,14 @@ impl Panel {
Ok(())
}

// /// return the last non empty pattern used in a previous state
// pub fn last_pattern(&self) -> Option<&InputPattern> {
// for state in self.states.iter().rev().skip(1) {
// let pattern = state.pattern();
// if pattern.is_some() {
// return Some(pattern);
// }
// }
// None
// }
}
150 changes: 83 additions & 67 deletions src/browser/browser_state.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use {
crate::{
app::*,
command::{Command, TriggerType},
command::*,
display::{DisplayableTree, Screen, W},
errors::{ProgramError, TreeBuildError},
flag::Flag,
Expand Down Expand Up @@ -374,82 +374,46 @@ impl PanelState for BrowserState {
cc,
)
}
Internal::select => internal_select::on_internal(
internal_exec,
input_invocation,
trigger_type,
self.displayed_tree_mut(),
app_state,
cc,
),
Internal::up_tree => match self.displayed_tree().root().parent() {
Some(path) => internal_focus::on_path(
path.to_path_buf(),
screen,
self.displayed_tree().options.clone(),
bang,
con,
),
None => CmdResult::error("no parent found"),
},
Internal::open_stay => self.open_selection_stay_in_broot(screen, con, bang, false)?,
Internal::open_stay_filter => self.open_selection_stay_in_broot(screen, con, bang, true)?,
Internal::line_down => {
let count = get_arg(input_invocation, internal_exec, 1);
self.displayed_tree_mut().move_selection(count, page_height, true);
CmdResult::Keep
}
Internal::line_up => {
Internal::line_down_no_cycle => {
let count = get_arg(input_invocation, internal_exec, 1);
self.displayed_tree_mut().move_selection(-count, page_height, true);
self.displayed_tree_mut().move_selection(count, page_height, false);
CmdResult::Keep
}
Internal::line_down_no_cycle => {
Internal::line_up => {
let count = get_arg(input_invocation, internal_exec, 1);
self.displayed_tree_mut().move_selection(count, page_height, false);
self.displayed_tree_mut().move_selection(-count, page_height, true);
CmdResult::Keep
}
Internal::line_up_no_cycle => {
let count = get_arg(input_invocation, internal_exec, 1);
self.displayed_tree_mut().move_selection(-count, page_height, false);
CmdResult::Keep
}
Internal::previous_dir => {
self.displayed_tree_mut().try_select_previous_filtered(
|line| line.is_dir(),
page_height,
);
CmdResult::Keep
}
Internal::next_dir => {
self.displayed_tree_mut().try_select_next_filtered(
|line| line.is_dir(),
page_height,
);
CmdResult::Keep
}
Internal::previous_match => {
self.displayed_tree_mut().try_select_previous_filtered(
|line| line.direct_match,
page_height,
);
CmdResult::Keep
}
Internal::next_match => {
self.displayed_tree_mut().try_select_next_filtered(
|line| line.direct_match,
page_height,
);
CmdResult::Keep
}
Internal::previous_same_depth => {
self.displayed_tree_mut().try_select_previous_same_depth(page_height);
CmdResult::Keep
}
Internal::next_same_depth => {
self.displayed_tree_mut().try_select_next_same_depth(page_height);
CmdResult::Keep
}
Internal::open_stay => self.open_selection_stay_in_broot(screen, con, bang, false)?,
Internal::open_stay_filter => self.open_selection_stay_in_broot(screen, con, bang, true)?,
Internal::page_down => {
let tree = self.displayed_tree_mut();
if !tree.try_scroll(page_height as i32, page_height) {
Expand Down Expand Up @@ -508,45 +472,97 @@ impl PanelState for BrowserState {
}
Internal::panel_right_no_open => CmdResult::HandleInApp(Internal::panel_right_no_open),
Internal::parent => self.go_to_parent(screen, con, bang),
Internal::previous_dir => {
self.displayed_tree_mut().try_select_previous_filtered(
|line| line.is_dir(),
page_height,
);
CmdResult::Keep
}
Internal::previous_match => {
self.displayed_tree_mut().try_select_previous_filtered(
|line| line.direct_match,
page_height,
);
CmdResult::Keep
}
Internal::previous_same_depth => {
self.displayed_tree_mut().try_select_previous_same_depth(page_height);
CmdResult::Keep
}
Internal::print_tree => {
print::print_tree(self.displayed_tree(), cc.app.screen, cc.app.panel_skin, con)?
}
Internal::root_up => {
Internal::quit => CmdResult::Quit,
Internal::root_down => {
let tree = self.displayed_tree();
let root = tree.root();
if let Some(new_root) = root.parent() {
if tree.selection > 0 {
let root_len = tree.root().components().count();
let new_root = tree.selected_line().path
.components()
.take(root_len + 1)
.collect();
self.modified(
screen,
new_root.to_path_buf(),
new_root,
tree.options.clone(),
None,
bang,
con,
)
} else {
CmdResult::error(format!("{root:?} has no parent"))
CmdResult::error("No selected line")
}
}
Internal::root_down => {
Internal::root_up => {
let tree = self.displayed_tree();
if tree.selection > 0 {
let root_len = tree.root().components().count();
let new_root = tree.selected_line().path
.components()
.take(root_len + 1)
.collect();
let root = tree.root();
if let Some(new_root) = root.parent() {
self.modified(
screen,
new_root,
new_root.to_path_buf(),
tree.options.clone(),
None,
bang,
con,
)
} else {
CmdResult::error("No selected line")
CmdResult::error(format!("{root:?} has no parent"))
}
}
Internal::search_again => {
match self.filtered_tree.as_ref().map(|t| t.total_search) {
None => {
// we delegate to the app the task of looking for a preview pattern
// used before this state
CmdResult::HandleInApp(Internal::search_again)
}
Some(true) => {
CmdResult::error("search was already total: all possible matches have been ranked")
}
Some(false) => {
self.search(self.displayed_tree().options.pattern.clone(), true);
CmdResult::Keep
}
}
}
Internal::select => internal_select::on_internal(
internal_exec,
input_invocation,
trigger_type,
self.displayed_tree_mut(),
app_state,
cc,
),
Internal::select_first => {
self.displayed_tree_mut().try_select_first();
CmdResult::Keep
}
Internal::select_last => {
let page_height = BrowserState::page_height(screen);
self.displayed_tree_mut().try_select_last(page_height);
CmdResult::Keep
}
Internal::stage_all_directories => {
let pattern = self.displayed_tree().options.pattern.clone();
let file_type_condition = FileTypeCondition::Directory;
Expand Down Expand Up @@ -577,15 +593,6 @@ impl PanelState for BrowserState {
CmdResult::Keep
}
}
Internal::select_first => {
self.displayed_tree_mut().try_select_first();
CmdResult::Keep
}
Internal::select_last => {
let page_height = BrowserState::page_height(screen);
self.displayed_tree_mut().try_select_last(page_height);
CmdResult::Keep
}
Internal::start_end_panel => {
if cc.panel.purpose.is_arg_edition() {
debug!("start_end understood as end");
Expand Down Expand Up @@ -652,7 +659,16 @@ impl PanelState for BrowserState {
#[cfg(not(feature = "trash"))]
CmdResult::DisplayError("feature not enabled or platform does not support trash".into())
}
Internal::quit => CmdResult::Quit,
Internal::up_tree => match self.displayed_tree().root().parent() {
Some(path) => internal_focus::on_path(
path.to_path_buf(),
screen,
self.displayed_tree().options.clone(),
bang,
con,
),
None => CmdResult::error("no parent found"),
},
_ => self.on_internal_generic(
w,
invocation_parser,
Expand Down
1 change: 1 addition & 0 deletions src/verb/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ Internals! {
toggle_tree: "toggle showing more than one level of the tree" true,
toggle_trim_root: "toggle removing nodes at first level too" false,
total_search: "search again but on all children" false,
search_again: "either put pack the search, or search deeper" false,
trash: "move file to system trash" true,
unstage: "remove selection from staging area" true,
up_tree: "focus the parent of the current root" true,
Expand Down
3 changes: 2 additions & 1 deletion src/verb/verb_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ impl VerbStore {
self.add_internal(toggle_perm).with_shortcut("perm");
self.add_internal(toggle_sizes).with_shortcut("sizes");
self.add_internal(toggle_trim_root);
self.add_internal(total_search).with_key(key!(ctrl-s));
self.add_internal(total_search);
self.add_internal(search_again).with_key(key!(ctrl-s));
self.add_internal(up_tree).with_shortcut("up");

self.add_internal(clear_output);
Expand Down
Loading