feat: bind Ctrl-U to backward line deletion

This commit is contained in:
2026-10-12 18:27:58 +02:00
parent 2260817fc0
commit 1cd56cf3f6
4 changed files with 67 additions and 7 deletions
+60 -2
View File
@@ -1139,6 +1139,7 @@ fn default_bindings() -> HashMap<Mode, HashMap<Input, Binding>> {
for (key, action) in [
(Input::Escape, Normal),
(Input::Backspace, Backspace),
(Input::Ctrl('u'), BackspaceLine),
(
Input::Enter,
if mode == Mode::Insert {
@@ -5032,6 +5033,11 @@ impl Editor {
self.palette = None;
self.pane_close_picker_origin = None;
}
Input::Ctrl('u') => {
if BackspaceKind::Line.truncate(&mut palette.query) {
self.refresh_palette();
}
}
Input::Enter => {
let entry = palette
.entries
@@ -15002,7 +15008,7 @@ mod tests {
}
#[test]
fn filter_clear_respects_navigation_bindings_and_does_not_clear_palette_or_idle_dock() {
fn filter_clear_respects_navigation_bindings_and_preserves_idle_dock_queries() {
let directory = Directory::new();
for name in ["a.txt", "b.txt"] {
fs::write(directory.path(name), "text").unwrap();
@@ -15045,7 +15051,7 @@ mod tests {
editor.handle(Input::Ctrl('p'));
type_text(&mut editor, "core");
editor.handle(Input::Ctrl('u'));
assert_eq!(editor.palette().unwrap().query, "core");
assert!(editor.palette().unwrap().query.is_empty());
assert_eq!(editor.file_picker().unwrap().query, "txt");
}
}
@@ -16245,6 +16251,14 @@ mod tests {
let revision = editor.text_revision();
let carets = editor.carets();
editor.handle(opening);
type_text(&mut editor, "discard this query");
editor.handle(Input::Ctrl('u'));
assert_eq!(
editor
.palette()
.map_or(editor.command_line(), |palette| palette.query.as_str()),
""
);
type_text(&mut editor, "alpha βeta ");
editor.handle(Input::AltBackspace);
assert_eq!(
@@ -16266,6 +16280,50 @@ mod tests {
}
}
#[test]
fn ctrl_u_deletes_line_prefixes_and_honors_disabled_and_remapped_bindings() {
let mut editor = editor();
let original = "first\nalpha βeta tail\nlast";
editor
.apply(vec![Effect::Replace(original.into())])
.unwrap();
set_carets(&mut editor, &[(1, 11)], 0);
editor.handle(Input::Char('i'));
editor.handle(Input::Ctrl('u'));
assert_eq!(editor.context().text, "first\ntail\nlast");
assert_eq!(editor.cursor(), Cursor { row: 1, column: 0 });
assert_eq!(editor.mode(), Mode::Insert);
editor.handle(Input::Escape);
editor.handle(Input::Char('u'));
assert_eq!(editor.context().text, original);
editor.bind("insert", "ctrl+u", None).unwrap();
editor.handle(Input::Char('i'));
editor.handle(Input::Ctrl('u'));
assert_eq!(editor.context().text, original);
editor
.bind("insert", "ctrl+u", Some("core.backspace_word".into()))
.unwrap();
editor.handle(Input::Ctrl('u'));
assert_eq!(editor.context().text, "first\nalpha tail\nlast");
editor.handle(Input::Escape);
for (opening, mode) in [(':', "command"), ('/', "search")] {
editor.bind(mode, "ctrl+u", None).unwrap();
editor.handle(Input::Char(opening));
type_text(&mut editor, "alpha beta");
editor.handle(Input::Ctrl('u'));
assert_eq!(editor.command_line(), "alpha beta");
editor
.bind(mode, "ctrl+u", Some("core.backspace_word".into()))
.unwrap();
editor.handle(Input::Ctrl('u'));
assert_eq!(editor.command_line(), "alpha ");
assert_eq!(editor.context().text, "first\nalpha tail\nlast");
editor.handle(Input::Escape);
}
}
#[test]
fn tree_leaf_search_opens_direct_match_and_directory_search_enters_browse() {
let directory = Directory::new();