Skip to content

Commit

Permalink
History menu pages (#342)
Browse files Browse the repository at this point in the history
* history menu page error

* checking before update

* remove in_edit variable

* remove redundant none
  • Loading branch information
elferherrera committed Mar 10, 2022
1 parent f60bbb2 commit 87a32d5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
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

0 comments on commit 87a32d5

Please sign in to comment.