parent
1e595431c0
commit
9ece44e762
|
@ -395,56 +395,27 @@ impl<'a, N: Notify + 'a, T: EventListener> input::ActionContext<T> for ActionCon
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn push_search(&mut self, c: char) {
|
fn push_search(&mut self, c: char) {
|
||||||
let regex = match self.search_state.regex.as_mut() {
|
if let Some(regex) = self.search_state.regex.as_mut() {
|
||||||
Some(regex) => regex,
|
regex.push(c);
|
||||||
None => return,
|
self.update_search();
|
||||||
};
|
|
||||||
|
|
||||||
// Hide cursor while typing into the search bar.
|
|
||||||
if self.config.ui_config.mouse.hide_when_typing {
|
|
||||||
self.window.set_mouse_visible(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add new char to search string.
|
|
||||||
regex.push(c);
|
|
||||||
|
|
||||||
// Create terminal search from the new regex string.
|
|
||||||
self.terminal.start_search(®ex);
|
|
||||||
|
|
||||||
// Update search highlighting.
|
|
||||||
self.goto_match(MAX_SEARCH_WHILE_TYPING);
|
|
||||||
|
|
||||||
self.terminal.dirty = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn pop_search(&mut self) {
|
fn pop_search(&mut self) {
|
||||||
let regex = match self.search_state.regex.as_mut() {
|
if let Some(regex) = self.search_state.regex.as_mut() {
|
||||||
Some(regex) => regex,
|
regex.pop();
|
||||||
None => return,
|
self.update_search();
|
||||||
};
|
|
||||||
|
|
||||||
// Hide cursor while typing into the search bar.
|
|
||||||
if self.config.ui_config.mouse.hide_when_typing {
|
|
||||||
self.window.set_mouse_visible(false);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Remove last char from search string.
|
#[inline]
|
||||||
regex.pop();
|
fn pop_word_search(&mut self) {
|
||||||
|
if let Some(regex) = self.search_state.regex.as_mut() {
|
||||||
if regex.is_empty() {
|
*regex = regex.trim_end().to_owned();
|
||||||
// Stop search if there's nothing to search for.
|
regex.truncate(regex.rfind(' ').map(|i| i + 1).unwrap_or(0));
|
||||||
self.search_reset_state();
|
self.update_search();
|
||||||
self.terminal.cancel_search();
|
|
||||||
} else {
|
|
||||||
// Create terminal search from the new regex string.
|
|
||||||
self.terminal.start_search(®ex);
|
|
||||||
|
|
||||||
// Update search highlighting.
|
|
||||||
self.goto_match(MAX_SEARCH_WHILE_TYPING);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.terminal.dirty = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -483,6 +454,32 @@ impl<'a, N: Notify + 'a, T: EventListener> input::ActionContext<T> for ActionCon
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, N: Notify + 'a, T: EventListener> ActionContext<'a, N, T> {
|
impl<'a, N: Notify + 'a, T: EventListener> ActionContext<'a, N, T> {
|
||||||
|
fn update_search(&mut self) {
|
||||||
|
let regex = match self.search_state.regex.as_mut() {
|
||||||
|
Some(regex) => regex,
|
||||||
|
None => return,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Hide cursor while typing into the search bar.
|
||||||
|
if self.config.ui_config.mouse.hide_when_typing {
|
||||||
|
self.window.set_mouse_visible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if regex.is_empty() {
|
||||||
|
// Stop search if there's nothing to search for.
|
||||||
|
self.search_reset_state();
|
||||||
|
self.terminal.cancel_search();
|
||||||
|
} else {
|
||||||
|
// Create terminal search from the new regex string.
|
||||||
|
self.terminal.start_search(®ex);
|
||||||
|
|
||||||
|
// Update search highlighting.
|
||||||
|
self.goto_match(MAX_SEARCH_WHILE_TYPING);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.terminal.dirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
/// Reset terminal to the state before search was started.
|
/// Reset terminal to the state before search was started.
|
||||||
fn search_reset_state(&mut self) {
|
fn search_reset_state(&mut self) {
|
||||||
// Reset display offset.
|
// Reset display offset.
|
||||||
|
|
|
@ -99,6 +99,7 @@ pub trait ActionContext<T: EventListener> {
|
||||||
fn cancel_search(&mut self);
|
fn cancel_search(&mut self);
|
||||||
fn push_search(&mut self, c: char);
|
fn push_search(&mut self, c: char);
|
||||||
fn pop_search(&mut self);
|
fn pop_search(&mut self);
|
||||||
|
fn pop_word_search(&mut self);
|
||||||
fn search_direction(&self) -> Direction;
|
fn search_direction(&self) -> Direction;
|
||||||
fn search_active(&self) -> bool;
|
fn search_active(&self) -> bool;
|
||||||
}
|
}
|
||||||
|
@ -807,19 +808,34 @@ impl<'a, T: EventListener, A: ActionContext<T>> Processor<'a, T, A> {
|
||||||
pub fn key_input(&mut self, input: KeyboardInput) {
|
pub fn key_input(&mut self, input: KeyboardInput) {
|
||||||
match input.state {
|
match input.state {
|
||||||
ElementState::Pressed if self.ctx.search_active() => {
|
ElementState::Pressed if self.ctx.search_active() => {
|
||||||
match input.virtual_keycode {
|
match (input.virtual_keycode, *self.ctx.modifiers()) {
|
||||||
Some(VirtualKeyCode::Back) => {
|
(Some(VirtualKeyCode::Back), _) => {
|
||||||
self.ctx.pop_search();
|
self.ctx.pop_search();
|
||||||
*self.ctx.suppress_chars() = true;
|
*self.ctx.suppress_chars() = true;
|
||||||
},
|
},
|
||||||
Some(VirtualKeyCode::Return) => {
|
(Some(VirtualKeyCode::Return), _)
|
||||||
|
| (Some(VirtualKeyCode::J), ModifiersState::CTRL) => {
|
||||||
self.ctx.confirm_search();
|
self.ctx.confirm_search();
|
||||||
*self.ctx.suppress_chars() = true;
|
*self.ctx.suppress_chars() = true;
|
||||||
},
|
},
|
||||||
Some(VirtualKeyCode::Escape) => {
|
(Some(VirtualKeyCode::Escape), _) => {
|
||||||
self.ctx.cancel_search();
|
self.ctx.cancel_search();
|
||||||
*self.ctx.suppress_chars() = true;
|
*self.ctx.suppress_chars() = true;
|
||||||
},
|
},
|
||||||
|
(Some(VirtualKeyCode::U), ModifiersState::CTRL) => {
|
||||||
|
let direction = self.ctx.search_direction();
|
||||||
|
self.ctx.cancel_search();
|
||||||
|
self.ctx.start_search(direction);
|
||||||
|
*self.ctx.suppress_chars() = true;
|
||||||
|
},
|
||||||
|
(Some(VirtualKeyCode::H), ModifiersState::CTRL) => {
|
||||||
|
self.ctx.pop_search();
|
||||||
|
*self.ctx.suppress_chars() = true;
|
||||||
|
},
|
||||||
|
(Some(VirtualKeyCode::W), ModifiersState::CTRL) => {
|
||||||
|
self.ctx.pop_word_search();
|
||||||
|
*self.ctx.suppress_chars() = true;
|
||||||
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1127,6 +1143,8 @@ mod tests {
|
||||||
|
|
||||||
fn pop_search(&mut self) {}
|
fn pop_search(&mut self) {}
|
||||||
|
|
||||||
|
fn pop_word_search(&mut self) {}
|
||||||
|
|
||||||
fn search_direction(&self) -> Direction {
|
fn search_direction(&self) -> Direction {
|
||||||
Direction::Right
|
Direction::Right
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue