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

Bang command expands only alone in buffer #336

Merged
merged 1 commit into from
Mar 7, 2022
Merged
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
bang command expands only alone in buffer
  • Loading branch information
elferherrera committed Mar 7, 2022
commit 9d0d39afb672cc15261aaebdafd32a24559eaeda
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