feat(tui): support Ctrl+Backspace in text inputs

This commit is contained in:
objz committed 2026-07-28 16:46:15 +02:00
1 parent 315567a79c
commit cccf65981a
13 files changed
+99 -16

No files matched your search

+1 -1
View File
@@ -138,7 +138,7 @@ pub fn handle_key(key_event: &KeyEvent, state: &mut AccountState) -> bool {
}
KeyCode::Backspace => {
let mut new_name = name.clone();
new_name.pop();
super::search::backspace(&mut new_name, key_event.modifiers);
state.add_mode = AddMode::OfflineNameInput(new_name);
true
}
+1 -1
View File
@@ -934,7 +934,7 @@ pub fn handle_key(key_event: &KeyEvent, state: &mut DiscoveryState) -> bool {
match key_event.code {
KeyCode::Enter => state.search.confirm(),
KeyCode::Esc => state.search.deactivate(),
KeyCode::Backspace => state.search.pop(),
KeyCode::Backspace => state.search.backspace(key_event.modifiers),
KeyCode::Char(c) => state.search.push(c),
_ => {}
}
+1 -1
View File
@@ -1268,7 +1268,7 @@ fn handle_search_keys(key_event: &KeyEvent, state: &mut ContentListState) -> boo
state.update_scrollbar();
}
KeyCode::Backspace => {
state.search.pop();
state.search.backspace(key_event.modifiers);
state.list_state.selected = Some(0);
state.update_scrollbar();
}
+1 -1
View File
@@ -180,7 +180,7 @@ impl WidgetKey for State {
self.update_scrollbar();
}
KeyCode::Backspace => {
self.search.pop();
self.search.backspace(key_event.modifiers);
self.list_state.selected = Some(0);
self.update_scrollbar();
}
+2 -2
View File
@@ -313,7 +313,7 @@ pub fn handle_key(key_event: &KeyEvent, state: &mut LogsState) -> bool {
state.viewer_scroll = 0;
}
KeyCode::Backspace => {
state.viewer_search.pop();
state.viewer_search.backspace(key_event.modifiers);
state.viewer_scroll = 0;
}
KeyCode::Char(c) => {
@@ -384,7 +384,7 @@ pub fn handle_key(key_event: &KeyEvent, state: &mut LogsState) -> bool {
state.update_scrollbar();
}
KeyCode::Backspace => {
state.search.pop();
state.search.backspace(key_event.modifiers);
state.list_state.selected = Some(0);
state.load_selected_content();
state.update_scrollbar();
@@ -235,7 +235,7 @@ fn handle_input_key(
match key_event.code {
KeyCode::Esc => state.step = ImportStep::Discover,
KeyCode::Backspace => {
state.input.pop();
crate::tui::widgets::search::backspace(&mut state.input, key_event.modifiers);
}
KeyCode::Enter => {
if state.input.trim().is_empty() {
@@ -273,7 +273,7 @@ fn handle_version_key(
return;
}
KeyCode::Backspace => {
state.version_search.pop();
state.version_search.backspace(key_event.modifiers);
clamp_version_index(state);
return;
}
+13 -1
View File
@@ -147,6 +147,18 @@ fn handle_name_key(
}
state.step = WizardStep::Loader;
}
KeyCode::Backspace
if key_event
.modifiers
.contains(crossterm::event::KeyModifiers::CONTROL) =>
{
let position = state.name_state.position();
let position = crate::tui::widgets::search::delete_previous_word(
state.name_state.value_mut(),
position,
);
*state.name_state.position_mut() = position;
}
_ => {
state.name_state.handle_key_event(*key_event);
}
@@ -167,7 +179,7 @@ fn handle_version_key(
return;
}
KeyCode::Backspace => {
state.version_search.pop();
state.version_search.backspace(key_event.modifiers);
clamp_version_index(state);
return;
}
+1 -1
View File
@@ -248,7 +248,7 @@ pub fn handle_key(key_event: &KeyEvent, state: &mut ScreenshotsState) -> bool {
state.scroll_row = 0;
}
KeyCode::Backspace => {
state.search.pop();
state.search.backspace(key_event.modifiers);
state.selected = 0;
state.scroll_row = 0;
}
+27 -2
View File
@@ -1,6 +1,7 @@
// reusable incremental search state used across multiple widgets.
// handles case-insensitive filtering and inline match highlighting.
use crossterm::event::KeyModifiers;
use ratatui::{
style::{Modifier, Style},
text::{Line, Span},
@@ -34,8 +35,8 @@ impl SearchState {
self.query.push(c);
}
pub fn pop(&mut self) {
self.query.pop();
pub fn backspace(&mut self, modifiers: KeyModifiers) {
backspace(&mut self.query, modifiers);
}
pub fn is_empty(&self) -> bool {
@@ -117,6 +118,30 @@ impl SearchState {
}
}
pub fn backspace(text: &mut String, modifiers: KeyModifiers) {
if modifiers.contains(KeyModifiers::CONTROL) {
let cursor = text.chars().count();
delete_previous_word(text, cursor);
} else {
text.pop();
}
}
pub fn delete_previous_word(text: &mut String, cursor: usize) -> usize {
let mut chars = text.chars().collect::<Vec<_>>();
let cursor = cursor.min(chars.len());
let mut start = cursor;
while start > 0 && chars[start - 1].is_whitespace() {
start -= 1;
}
while start > 0 && !chars[start - 1].is_whitespace() {
start -= 1;
}
chars.drain(start..cursor);
*text = chars.into_iter().collect();
start
}
#[cfg(test)]
#[path = "../tests/widgets/search.rs"]
mod tests;
+1 -1
View File
@@ -491,7 +491,7 @@ pub fn handle_key(
}
KeyCode::Backspace => {
let mut new_name = name.clone();
new_name.pop();
super::search::backspace(&mut new_name, key_event.modifiers);
state.add_mode = AddMode::ProfileName(new_name);
return SettingsAction::None;
}