summaryrefslogtreecommitdiffstats
path: root/src/minibuffer.rs
diff options
context:
space:
mode:
authorrabite <rabite@posteo.de>2019-05-08 13:47:36 +0200
committerrabite <rabite@posteo.de>2019-05-08 13:48:46 +0200
commit572a217e17b0cc2c30cd94b57e5a94ede75e0707 (patch)
treefcf713135acb4516d4f935565d6b836eba525c21 /src/minibuffer.rs
parent7d08e6b064a0def48df927cd19572b1964aedcc8 (diff)
add incremental search/filter
Diffstat (limited to 'src/minibuffer.rs')
-rw-r--r--src/minibuffer.rs46
1 files changed, 36 insertions, 10 deletions
diff --git a/src/minibuffer.rs b/src/minibuffer.rs
index 6cc0081..a8fb410 100644
--- a/src/minibuffer.rs
+++ b/src/minibuffer.rs
@@ -135,7 +135,8 @@ pub struct MiniBuffer {
position: usize,
history: History,
completions: Vec<String>,
- last_completion: Option<String>
+ last_completion: Option<String>,
+ continuous: bool
}
impl MiniBuffer {
@@ -152,30 +153,43 @@ impl MiniBuffer {
position: 0,
history: History::new(),
completions: vec![],
- last_completion: None
+ last_completion: None,
+ continuous: false
}
}
- pub fn query(&mut self, query: &str) -> HResult<String> {
- self.query = query.to_string();
- self.input.clear();
- self.position = 0;
- self.history.reset();
- self.completions.clear();
- self.last_completion = None;
+ pub fn query(&mut self, query: &str, cont: bool) -> HResult<String> {
+ self.continuous = cont;
+
+ if !cont || self.query != query {
+ self.query = query.to_string();
+
+ self.clear();
+ }
self.screen()?.cursor_hide().log();
match self.popup() {
Err(HError::MiniBufferCancelledInput) => self.input_cancelled()?,
+ err @ Err(HError::MiniBufferInputUpdated(_)) => err?,
_ => {}
};
- if self.input == "" { self.input_empty()?; }
+ if self.input == "" {
+ self.clear();
+ self.input_empty()?; }
Ok(self.input.clone())
}
+ pub fn clear(&mut self) {
+ self.input.clear();
+ self.position = 0;
+ self.history.reset();
+ self.completions.clear();
+ self.last_completion = None;
+ }
+
pub fn complete(&mut self) -> HResult<()> {
if !self.input.ends_with(" ") {
if !self.completions.is_empty() {
@@ -325,6 +339,10 @@ impl MiniBuffer {
return HError::minibuffer_cancel()
}
+ pub fn input_updated(&self) -> HResult<()> {
+ return HError::input_updated(self.input.clone())
+ }
+
pub fn input_empty(&self) -> HResult<()> {
self.show_status("Empty!").log();
return HError::minibuffer_empty()
@@ -413,8 +431,11 @@ impl Widget for MiniBuffer {
}
fn on_key(&mut self, key: Key) -> HResult<()> {
+ let prev_input = self.input.clone();
+
match key {
Key::Esc | Key::Ctrl('c') => {
+ self.clear();
self.input_cancelled()?;
},
Key::Char('\n') => {
@@ -468,6 +489,11 @@ impl Widget for MiniBuffer {
}
_ => { }
}
+
+ if self.continuous && prev_input != self.input {
+ self.input_updated()?;
+ }
+
Ok(())
}