added search functionality
This commit is contained in:
@@ -64,6 +64,7 @@ where
|
||||
match self.app.mode {
|
||||
Mode::Normal => self.handle_normal_mode(key),
|
||||
Mode::Insert => self.handle_insert_mode(key),
|
||||
Mode::Search => self.handle_search_mode(key),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,6 +119,13 @@ where
|
||||
self.sync_command_status();
|
||||
} else if c_str == "q" {
|
||||
self.app.running = false;
|
||||
} else if c_str == self.config.keybinds.search {
|
||||
self.app.mode = Mode::Search;
|
||||
self.app.status_message = Some(format!("{} ", self.config.keybinds.search));
|
||||
} else if c_str == self.config.keybinds.next_match {
|
||||
self.app.jump_next_match();
|
||||
} else if c_str == self.config.keybinds.previous_match {
|
||||
self.app.jump_previous_match();
|
||||
}
|
||||
} else {
|
||||
match key.code {
|
||||
@@ -143,6 +151,28 @@ where
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Handles search mode key events.
|
||||
fn handle_search_mode(&mut self, key: KeyEvent) -> io::Result<()> {
|
||||
match key.code {
|
||||
KeyCode::Enter | KeyCode::Esc => {
|
||||
self.app.mode = Mode::Normal;
|
||||
self.app.status_message = None;
|
||||
}
|
||||
KeyCode::Backspace => {
|
||||
self.app.search_query.pop();
|
||||
self.app.status_message = Some(format!("{}{}", self.config.keybinds.search, self.app.search_query));
|
||||
self.app.jump_next_match();
|
||||
}
|
||||
KeyCode::Char(c) => {
|
||||
self.app.search_query.push(c);
|
||||
self.app.status_message = Some(format!("{}{}", self.config.keybinds.search, self.app.search_query));
|
||||
self.app.jump_next_match();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Logic to map command strings (like ":w") to internal application actions.
|
||||
fn execute_command(&mut self, cmd: &str) -> io::Result<()> {
|
||||
if cmd == self.config.keybinds.save {
|
||||
|
||||
Reference in New Issue
Block a user