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

History menu pages #342

Merged
merged 5 commits into from
Mar 10, 2022
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
17 changes: 7 additions & 10 deletions src/menu/history_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ impl<'a> Sum<&'a Page> for Page {
}

/// Struct to store the menu style

/// Context menu definition
pub struct HistoryMenu {
/// Menu coloring
Expand Down Expand Up @@ -64,8 +63,6 @@ pub struct HistoryMenu {
page: usize,
/// Event sent to the menu
event: Option<MenuEvent>,
/// Menu in edit mode
in_edit: bool,
/// String collected after the menu is activated
input: Option<String>,
}
Expand All @@ -86,7 +83,6 @@ impl Default for HistoryMenu {
multiline_marker: ":::".to_string(),
pages: Vec::new(),
event: None,
in_edit: false,
input: None,
}
}
Expand Down Expand Up @@ -346,7 +342,6 @@ impl Menu for HistoryMenu {
fn menu_event(&mut self, event: MenuEvent) {
match &event {
MenuEvent::Activate(_) => self.active = true,
MenuEvent::Edit(_) => self.in_edit = true,
MenuEvent::Deactivate => {
self.active = false;
self.input = None;
Expand Down Expand Up @@ -374,9 +369,10 @@ impl Menu for HistoryMenu {

// If there are no row selector and the menu has an Edit event, this clears
// the position together with the pages vector
if self.in_edit && row.is_none() {
self.reset_position();
self.in_edit = false;
if let Some(MenuEvent::Edit(_)) = self.event {
if row.is_none() {
self.reset_position();
}
}

let values = if query.is_empty() {
Expand Down Expand Up @@ -446,7 +442,7 @@ impl Menu for HistoryMenu {
completer: &dyn Completer,
painter: &Painter,
) {
if let Some(event) = self.event.take() {
if let Some(event) = self.event.clone() {
match event {
MenuEvent::Activate(updated) => {
self.reset_position();
Expand All @@ -464,7 +460,6 @@ impl Menu for HistoryMenu {
MenuEvent::Deactivate => {
self.active = false;
self.input = None;
self.event = None;
}
MenuEvent::Edit(updated) => {
if !updated {
Expand Down Expand Up @@ -539,6 +534,8 @@ impl Menu for HistoryMenu {
self.update_values(line_buffer, history, completer);
}
}

self.event = None;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/menu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ impl Default for MenuTextStyle {
}

/// Defines all possible events that could happen with a menu.
#[derive(Clone)]
pub enum MenuEvent {
/// Activation event for the menu. When the bool is true it means that the values
/// have already being updated. This is true when the option `quick_completions` is true
Expand Down