diff --git a/crates/ui-patterns/src/patterns/presets/browser.rs b/crates/ui-patterns/src/patterns/presets/browser.rs index 0cad65247..9888632b3 100644 --- a/crates/ui-patterns/src/patterns/presets/browser.rs +++ b/crates/ui-patterns/src/patterns/presets/browser.rs @@ -489,6 +489,7 @@ enum Seen { Menu(K), Reorder(EditEvent>), Rename(EditEvent>), + Delete(Vec), } /// The events of a collection that the browser acts on, whatever its items report. @@ -502,6 +503,7 @@ fn seen(events: Vec>) -> Vec> { CollectionEvent::ContextMenu(request) => Some(Seen::Menu(request.key)), CollectionEvent::Reorder(edit) => Some(Seen::Reorder(edit)), CollectionEvent::Rename(edit) => Some(Seen::Rename(edit)), + CollectionEvent::Delete(keys) => Some(Seen::Delete(keys)), _ => None, }) .collect() @@ -695,6 +697,7 @@ impl PresetBrowser<'_, K> { .tail(&tail) .collapsible() .rename(true) + .deletable(true) .rows_stamp(stamp) .can_rename(rename_row) .can_drag(can_drag) @@ -741,6 +744,7 @@ impl PresetBrowser<'_, K> { .arrows_select(false) .selection(Bind::given(selection)) .rename(true) + .deletable(true) .rows_stamp(stamp) .can_rename(rename_row) .can_drag(can_drag) @@ -887,6 +891,17 @@ impl PresetBrowser<'_, K> { }; events.extend(edit.filter_map(moved).map(PresetEvent::Reorder)); } + // Delete and Backspace give the same event as the row menu's Delete and the footer button; an + // open rename field takes the keys itself. + Seen::Delete(keys) => { + for key in keys { + if let BrowserKey::Preset(key) = key + && can_delete.as_ref().is_none_or(|test| test.passes(&key)) + { + events.push(PresetEvent::Delete(key)); + } + } + } Seen::Rename(edit) => { let ended = matches!(edit.phase(), Some(GesturePhase::Commit) | None); if let (true, Some(rename)) = (ended, edit.value())