Add next_search_result and previous_search_result shortcuts
Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>pull/312/head
parent
0a74c7d0e5
commit
0114e69542
|
@ -747,8 +747,17 @@ Open list entry.
|
|||
Show next info message, if any
|
||||
.Pq Ql Em M-> \" default value
|
||||
.It Ic info_message_previous
|
||||
Show previous info message, if any
|
||||
.Pq Ql Em M-< \" default value
|
||||
Show previous info message, if any.
|
||||
.Pq Em M-< \" default value
|
||||
.It Ic focus_in_text_field
|
||||
Focus on a text field.
|
||||
.Pq Em Enter \" default value
|
||||
.It Ic next_search_result
|
||||
Scroll to next search result.
|
||||
.Pq Em n \" default value
|
||||
.It Ic previous_search_result
|
||||
Scroll to previous search result.
|
||||
.Pq Em N
|
||||
.El
|
||||
.sp
|
||||
.Em listing
|
||||
|
|
|
@ -221,9 +221,11 @@ shortcut_key_values! { "general",
|
|||
home_page |> "Go to first page. (catch-all setting)" |> Key::Home,
|
||||
end_page |> "Go to last page. (catch-all setting)" |> Key::End,
|
||||
open_entry |> "Open list entry. (catch-all setting)" |> Key::Char('\n'),
|
||||
info_message_next |> "Show next info message, if any" |> Key::Alt('>'),
|
||||
info_message_previous |> "Show previous info message, if any" |> Key::Alt('<'),
|
||||
focus_in_text_field |> "Focus on a text field." |> Key::Char('\n')
|
||||
info_message_next |> "Show next info message, if any." |> Key::Alt('>'),
|
||||
info_message_previous |> "Show previous info message, if any." |> Key::Alt('<'),
|
||||
focus_in_text_field |> "Focus on a text field." |> Key::Char('\n'),
|
||||
next_search_result |> "Scroll to next search result." |> Key::Char('n'),
|
||||
previous_search_result |> "Scroll to previous search result." |> Key::Char('N')
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -51,12 +51,21 @@ use indexmap::IndexMap;
|
|||
pub use self::tables::*;
|
||||
use crate::{components::ExtendShortcutsMaps, jobs::JobId, melib::text_processing::TextProcessing};
|
||||
|
||||
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)]
|
||||
pub enum SearchMovement {
|
||||
Previous,
|
||||
#[default]
|
||||
Next,
|
||||
First,
|
||||
Last,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone)]
|
||||
pub struct SearchPattern {
|
||||
pattern: String,
|
||||
positions: Vec<(usize, usize)>,
|
||||
cursor: usize,
|
||||
movement: Option<PageMovement>,
|
||||
movement: Option<SearchMovement>,
|
||||
}
|
||||
|
||||
/// Status bar.
|
||||
|
@ -1215,7 +1224,7 @@ impl Component for Tabbed {
|
|||
if !search.positions.is_empty() {
|
||||
if let Some(mvm) = search.movement.take() {
|
||||
match mvm {
|
||||
PageMovement::Home => {
|
||||
SearchMovement::First => {
|
||||
if self.help_view.cursor.1 > search.positions[search.cursor].0 {
|
||||
self.help_view.cursor.1 = search.positions[search.cursor].0;
|
||||
}
|
||||
|
@ -1225,12 +1234,12 @@ impl Component for Tabbed {
|
|||
self.help_view.cursor.1 = search.positions[search.cursor].0;
|
||||
}
|
||||
}
|
||||
PageMovement::Up(_) => {
|
||||
SearchMovement::Previous => {
|
||||
if self.help_view.cursor.1 > search.positions[search.cursor].0 {
|
||||
self.help_view.cursor.1 = search.positions[search.cursor].0;
|
||||
}
|
||||
}
|
||||
PageMovement::Down(_) => {
|
||||
SearchMovement::Next => {
|
||||
if self.help_view.cursor.1 + rows
|
||||
< search.positions[search.cursor].0
|
||||
{
|
||||
|
@ -1415,16 +1424,18 @@ impl Component for Tabbed {
|
|||
pattern: pattern.to_string(),
|
||||
positions: vec![],
|
||||
cursor: 0,
|
||||
movement: Some(PageMovement::Home),
|
||||
movement: Some(SearchMovement::First),
|
||||
});
|
||||
self.dirty = true;
|
||||
return true;
|
||||
}
|
||||
UIEvent::Input(Key::Char('n'))
|
||||
if self.show_shortcuts && self.help_view.search.is_some() =>
|
||||
UIEvent::Input(ref key)
|
||||
if shortcut!(key == shortcuts[Shortcuts::GENERAL]["next_search_result"])
|
||||
&& self.show_shortcuts
|
||||
&& self.help_view.search.is_some() =>
|
||||
{
|
||||
if let Some(ref mut search) = self.help_view.search {
|
||||
search.movement = Some(PageMovement::Down(1));
|
||||
search.movement = Some(SearchMovement::Next);
|
||||
search.cursor += 1;
|
||||
} else {
|
||||
unsafe {
|
||||
|
@ -1434,11 +1445,13 @@ impl Component for Tabbed {
|
|||
self.dirty = true;
|
||||
return true;
|
||||
}
|
||||
UIEvent::Input(Key::Char('N'))
|
||||
if self.show_shortcuts && self.help_view.search.is_some() =>
|
||||
UIEvent::Input(ref key)
|
||||
if shortcut!(key == shortcuts[Shortcuts::GENERAL]["previous_search_result"])
|
||||
&& self.show_shortcuts
|
||||
&& self.help_view.search.is_some() =>
|
||||
{
|
||||
if let Some(ref mut search) = self.help_view.search {
|
||||
search.movement = Some(PageMovement::Up(1));
|
||||
search.movement = Some(SearchMovement::Previous);
|
||||
search.cursor = search.cursor.saturating_sub(1);
|
||||
} else {
|
||||
unsafe {
|
||||
|
|
|
@ -537,17 +537,19 @@ impl Component for Pager {
|
|||
if !search.positions.is_empty() {
|
||||
if let Some(mvm) = search.movement.take() {
|
||||
match mvm {
|
||||
PageMovement::Up(_) => {
|
||||
SearchMovement::First | SearchMovement::Last => {
|
||||
self.cursor.1 = search.positions[search.cursor].0;
|
||||
}
|
||||
SearchMovement::Previous => {
|
||||
if self.cursor.1 > search.positions[search.cursor].0 {
|
||||
self.cursor.1 = search.positions[search.cursor].0;
|
||||
}
|
||||
}
|
||||
PageMovement::Down(_) => {
|
||||
if self.cursor.1 + height < search.positions[search.cursor].0 {
|
||||
SearchMovement::Next => {
|
||||
if self.cursor.1 + rows < search.positions[search.cursor].0 {
|
||||
self.cursor.1 = search.positions[search.cursor].0;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -767,24 +769,30 @@ impl Component for Pager {
|
|||
pattern: pattern.to_string(),
|
||||
positions: vec![],
|
||||
cursor: 0,
|
||||
movement: Some(PageMovement::Home),
|
||||
movement: Some(SearchMovement::First),
|
||||
});
|
||||
self.initialised = false;
|
||||
self.dirty = true;
|
||||
return true;
|
||||
}
|
||||
UIEvent::Input(Key::Char('n')) if self.search.is_some() => {
|
||||
UIEvent::Input(ref key)
|
||||
if shortcut!(key == shortcuts[Shortcuts::GENERAL]["next_search_result"])
|
||||
&& self.search.is_some() =>
|
||||
{
|
||||
if let Some(ref mut search) = self.search {
|
||||
search.movement = Some(PageMovement::Down(1));
|
||||
search.movement = Some(SearchMovement::Next);
|
||||
search.cursor += 1;
|
||||
self.initialised = false;
|
||||
self.dirty = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
UIEvent::Input(Key::Char('N')) if self.search.is_some() => {
|
||||
UIEvent::Input(ref key)
|
||||
if shortcut!(key == shortcuts[Shortcuts::GENERAL]["previous_search_result"])
|
||||
&& self.search.is_some() =>
|
||||
{
|
||||
if let Some(ref mut search) = self.search {
|
||||
search.movement = Some(PageMovement::Up(1));
|
||||
search.movement = Some(SearchMovement::Previous);
|
||||
search.cursor = search.cursor.saturating_sub(1);
|
||||
self.initialised = false;
|
||||
self.dirty = true;
|
||||
|
|
Loading…
Reference in New Issue