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,5 +1,5 @@
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use tui_prompts::TextState;
use tui_prompts::{State as PromptState, TextState};
use super::*;
use crate::tests::TEST_LOCK;
@@ -70,3 +70,25 @@ fn version_filter_clamps_a_stale_selection() {
state.show_snapshots = true;
assert_eq!(visible_versions(&state).len(), 2);
}
#[test]
fn ctrl_backspace_deletes_the_word_before_the_name_cursor() {
let _guard = TEST_LOCK.lock().unwrap_or_else(|error| error.into_inner());
let mut instances = instances::State::default();
{
let mut state = WIZARD_STATE.lock().unwrap();
*state = WizardState::default();
state.name_state = TextState::new().with_value("hello brave world");
*state.name_state.position_mut() = "hello brave".chars().count();
}
handle_key(
&KeyEvent::new(KeyCode::Backspace, KeyModifiers::CONTROL),
&mut instances,
);
let state = WIZARD_STATE.lock().unwrap();
assert_eq!(state.name_state.value(), "hello world");
assert_eq!(state.name_state.position(), "hello ".chars().count());
}
+24
View File
@@ -1,4 +1,5 @@
use super::*;
use crossterm::event::KeyModifiers;
#[test]
fn confirm_keeps_query_but_deactivates() {
@@ -50,3 +51,26 @@ fn highlight_spans_marks_each_case_insensitive_match() {
assert!(spans[2].style.add_modifier.contains(Modifier::BOLD));
assert!(spans[2].style.add_modifier.contains(Modifier::UNDERLINED));
}
#[test]
fn ctrl_backspace_deletes_the_previous_word() {
let mut search = SearchState {
query: "alpha βeta ".to_owned(),
..SearchState::default()
};
search.backspace(KeyModifiers::CONTROL);
assert_eq!(search.query, "alpha ");
}
#[test]
fn deleting_a_word_before_the_cursor_preserves_the_suffix() {
let mut text = "hello brave world".to_owned();
let cursor = "hello brave".chars().count();
let cursor = delete_previous_word(&mut text, cursor);
assert_eq!(text, "hello world");
assert_eq!(cursor, "hello ".chars().count());
}