diff --git a/src/frontend/gui/search.rs b/src/frontend/gui/search.rs index bb077e030..8c38a8cb6 100644 --- a/src/frontend/gui/search.rs +++ b/src/frontend/gui/search.rs @@ -31,7 +31,7 @@ struct MatchResult { struct SearchRenderable { delegate: Rc, /// The text that the user entered - pattern: String, + pattern: Pattern, /// The most recently queried set of matches results: Vec, by_line: HashMap>, @@ -49,14 +49,14 @@ struct SearchRenderable { } impl SearchOverlay { - pub fn with_tab(term_window: &TermWindow, tab: &Rc) -> Rc { + pub fn with_tab(term_window: &TermWindow, tab: &Rc, pattern: Pattern) -> Rc { let viewport = term_window.get_viewport(tab.tab_id()); let dims = tab.renderer().get_dimensions(); let window = term_window.window.clone().unwrap(); let mut renderer = SearchRenderable { delegate: Rc::clone(tab), - pattern: String::new(), + pattern, results: vec![], by_line: HashMap::new(), dirty_results: RangeSet::default(), @@ -292,7 +292,7 @@ impl SearchRenderable { self.dirty_results.add(bar_pos); if !self.pattern.is_empty() { - self.results = self.delegate.search(&Pattern::String(self.pattern.clone())); + self.results = self.delegate.search(&self.pattern); self.results.sort(); self.recompute_results(); @@ -343,7 +343,7 @@ impl Renderable for SearchRenderable { 0, &format!( "Search: {} ({}/{} matches)", - self.pattern, + *self.pattern, self.result_pos.map(|x| x + 1).unwrap_or(0), self.results.len() ), diff --git a/src/frontend/gui/termwindow.rs b/src/frontend/gui/termwindow.rs index 501a6114e..25041551b 100644 --- a/src/frontend/gui/termwindow.rs +++ b/src/frontend/gui/termwindow.rs @@ -1489,8 +1489,8 @@ impl TermWindow { let window = self.window.as_ref().unwrap(); window.invalidate(); } - Search => { - let search = SearchOverlay::with_tab(self, tab); + Search(pattern) => { + let search = SearchOverlay::with_tab(self, tab, pattern.clone()); self.assign_overlay(tab.tab_id(), search); } }; diff --git a/src/keyassignment.rs b/src/keyassignment.rs index 20f7caf69..6c33fc77d 100644 --- a/src/keyassignment.rs +++ b/src/keyassignment.rs @@ -1,6 +1,7 @@ use crate::config::configuration; use crate::frontend::gui::SelectionMode; use crate::mux::domain::DomainId; +use crate::mux::tab::Pattern; use serde::{Deserialize, Serialize}; use std::collections::HashMap; use std::path::PathBuf; @@ -98,7 +99,7 @@ pub enum KeyAssignment { SpawnCommandInNewWindow(SpawnCommand), ShowLauncher, ClearScrollback, - Search, + Search(Pattern), SelectTextAtMouseCursor(SelectionMode), ExtendSelectionToMouseCursor(Option), @@ -163,8 +164,16 @@ impl InputMap { [ctrl_shift, KeyCode::Char('N'), SpawnWindow], [KeyModifiers::SUPER, KeyCode::Char('k'), ClearScrollback], [ctrl_shift, KeyCode::Char('K'), ClearScrollback], - [KeyModifiers::SUPER, KeyCode::Char('f'), Search], - [ctrl_shift, KeyCode::Char('F'), Search], + [ + KeyModifiers::SUPER, + KeyCode::Char('f'), + Search(Pattern::CaseSensitiveString("".into())) + ], + [ + ctrl_shift, + KeyCode::Char('F'), + Search(Pattern::CaseSensitiveString("".into())) + ], // Font size manipulation [KeyModifiers::CTRL, KeyCode::Char('-'), DecreaseFontSize], [KeyModifiers::CTRL, KeyCode::Char('0'), ResetFontSize], diff --git a/src/localtab.rs b/src/localtab.rs index fa2598ee2..f3b3f19cd 100644 --- a/src/localtab.rs +++ b/src/localtab.rs @@ -137,7 +137,7 @@ impl Tab for LocalTab { return; } match pattern { - Pattern::String(s) => { + Pattern::CaseSensitiveString(s) => { for (idx, s) in haystack.match_indices(s) { let (start_x, start_y) = haystack_idx_to_coord(idx, coords); let (end_x, end_y) = haystack_idx_to_coord(idx + s.len(), coords); diff --git a/src/mux/tab.rs b/src/mux/tab.rs index 03c2ca45e..82b149039 100644 --- a/src/mux/tab.rs +++ b/src/mux/tab.rs @@ -3,6 +3,7 @@ use crate::mux::renderable::Renderable; use crate::mux::Mux; use downcast_rs::{impl_downcast, Downcast}; use portable_pty::PtySize; +use serde::{Deserialize, Serialize}; use std::cell::RefMut; use std::sync::{Arc, Mutex}; use term::color::ColorPalette; @@ -44,11 +45,29 @@ fn schedule_next_paste(paste: &Arc>) { }); } +#[derive(Debug, Clone, Deserialize, Serialize)] pub enum Pattern { - String(String), + CaseSensitiveString(String), // Regex(regex::Regex), } +impl std::ops::Deref for Pattern { + type Target = String; + fn deref(&self) -> &String { + match self { + Pattern::CaseSensitiveString(s) => s, + } + } +} + +impl std::ops::DerefMut for Pattern { + fn deref_mut(&mut self) -> &mut String { + match self { + Pattern::CaseSensitiveString(s) => s, + } + } +} + #[derive(Debug, Clone, Copy, Eq, PartialEq, PartialOrd, Ord)] pub struct SearchResult { pub start_y: StableRowIndex,