Skip to content

Commit

Permalink
bang command expands only alone in buffer (#336)
Browse files Browse the repository at this point in the history
  • Loading branch information
elferherrera committed Mar 7, 2022
1 parent 0d6e262 commit 8394b62
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,6 @@ pub struct Reedline {

// Engine Menus
menus: Vec<Box<dyn Menu>>,

// Keeps track if a history entry was introduced using the ! (bang) command
replaced_history: bool,
}

impl Drop for Reedline {
Expand Down Expand Up @@ -152,7 +149,6 @@ impl Reedline {
animate: false,
use_ansi_coloring: true,
menus: Vec::new(),
replaced_history: false,
};

Ok(reedline)
Expand Down Expand Up @@ -727,13 +723,9 @@ impl Reedline {
}
}

if let Some(event) = self.replace_history_with_bang() {
if !self.replaced_history {
self.replaced_history = true;
return self.handle_editor_event(prompt, event);
}
if let Some(event) = self.parse_bang_command() {
return self.handle_editor_event(prompt, event);
}
self.replaced_history = false;

let buffer = self.editor.get_buffer().to_string();
if matches!(self.validator.validate(&buffer), ValidationResult::Complete) {
Expand Down Expand Up @@ -776,17 +768,12 @@ impl Reedline {
}

if self.editor.line_buffer().get_buffer().is_empty() {
self.replaced_history = false;
menu.menu_event(MenuEvent::Deactivate);
} else {
menu.menu_event(MenuEvent::Edit(self.quick_completions));
}
}

if self.editor.line_buffer().get_buffer().is_empty() {
self.replaced_history = false;
}

Ok(EventStatus::Handled)
}
ReedlineEvent::Mouse => Ok(EventStatus::Inapplicable),
Expand Down Expand Up @@ -1049,11 +1036,17 @@ impl Reedline {
}
}

/// Insert in the buffer a history input where the bang character is found
fn replace_history_with_bang(&mut self) -> Option<ReedlineEvent> {
/// Parses the ! command to replace entries from the history
fn parse_bang_command(&mut self) -> Option<ReedlineEvent> {
let buffer = self.editor.get_buffer();
let (string, index) = parse_selection_char(buffer, &'!');

if let Some((_, indicator)) = &index {
if &buffer.trim() != indicator {
return None;
}
}

let history_result = index.and_then(|(index, indicator)| {
if indicator == "!!" {
self.history
Expand Down Expand Up @@ -1084,7 +1077,7 @@ impl Reedline {
/// Repaint logic for the history reverse search
///
/// Overwrites the prompt indicator and highlights the search string
/// separately from the result bufer.
/// separately from the result buffer.
fn history_search_paint(&mut self, prompt: &dyn Prompt) -> Result<()> {
let navigation = self.history.get_navigation();

Expand Down

0 comments on commit 8394b62

Please sign in to comment.