feat(ui): add redraw (#1519)

replace old Ctrl-L shortcut and remove the opposite one (Ctrl-H).

fixes #1507.
This commit is contained in:
依云 2024-01-08 17:40:23 +08:00 committed by GitHub
parent 915bff6d28
commit 5bd0eed6c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,6 +44,7 @@ enum InputAction {
ReturnOriginal, ReturnOriginal,
ReturnQuery, ReturnQuery,
Continue, Continue,
Redraw,
} }
#[allow(clippy::struct_field_names)] #[allow(clippy::struct_field_names)]
@ -169,9 +170,6 @@ impl State {
KeyCode::Left => { KeyCode::Left => {
self.search.input.left(); self.search.input.left();
} }
KeyCode::Char('h') if ctrl => {
self.search.input.left();
}
KeyCode::Char('b') if ctrl => { KeyCode::Char('b') if ctrl => {
self.search.input.left(); self.search.input.left();
} }
@ -184,7 +182,6 @@ impl State {
.input .input
.next_word(&settings.word_chars, settings.word_jump_mode), .next_word(&settings.word_chars, settings.word_jump_mode),
KeyCode::Right => self.search.input.right(), KeyCode::Right => self.search.input.right(),
KeyCode::Char('l') if ctrl => self.search.input.right(),
KeyCode::Char('f') if ctrl => self.search.input.right(), KeyCode::Char('f') if ctrl => self.search.input.right(),
KeyCode::Char('a') if ctrl => self.search.input.start(), KeyCode::Char('a') if ctrl => self.search.input.start(),
KeyCode::Home => self.search.input.start(), KeyCode::Home => self.search.input.start(),
@ -286,6 +283,9 @@ impl State {
KeyCode::Char('p' | 'k') if ctrl && settings.invert => { KeyCode::Char('p' | 'k') if ctrl && settings.invert => {
self.scroll_down(1); self.scroll_down(1);
} }
KeyCode::Char('l') if ctrl => {
return InputAction::Redraw;
}
KeyCode::Char(c) => self.search.input.insert(c), KeyCode::Char(c) => self.search.input.insert(c),
KeyCode::PageDown if !settings.invert => { KeyCode::PageDown if !settings.invert => {
let scroll_len = self.results_state.max_entries() - settings.scroll_context_lines; let scroll_len = self.results_state.max_entries() - settings.scroll_context_lines;
@ -693,6 +693,10 @@ pub async fn history(
loop { loop {
match app.handle_input(settings, &event::read()?, &mut std::io::stdout())? { match app.handle_input(settings, &event::read()?, &mut std::io::stdout())? {
InputAction::Continue => {}, InputAction::Continue => {},
InputAction::Redraw => {
terminal.clear()?;
terminal.draw(|f| app.draw(f, &results, settings))?;
},
r => { r => {
accept = app.accept; accept = app.accept;
break 'render r; break 'render r;
@ -743,7 +747,7 @@ pub async fn history(
// * out of bounds -> usually implies no selected entry so we return the input // * out of bounds -> usually implies no selected entry so we return the input
Ok(app.search.input.into_inner()) Ok(app.search.input.into_inner())
} }
InputAction::Continue => { InputAction::Continue | InputAction::Redraw => {
unreachable!("should have been handled!") unreachable!("should have been handled!")
} }
} }