diff --git a/README.md b/README.md
index 1648430..1c5f6b6 100644
--- a/README.md
+++ b/README.md
@@ -397,6 +397,8 @@ rescan, ⌘[ and ⌘] for back and forward, and ⌘Q, ⌘H and ⌘W (closing the
window quits); other ⌘ chords are left to the system. On Linux and Windows
the same work with ctrl, with F5 to rescan too.
+The key list closes with `esc`, its Close button, or a click outside it.
+
On the review screen: `m` trash, `p` permanent, `!` unmark all, `enter`
commits, `esc` goes back. Or hand the list on instead of acting on it: `s`
saves it as a text file, one path per line, and `a` copies a prompt for a
diff --git a/crates/disktree-app/src/tests.rs b/crates/disktree-app/src/tests.rs
index e219a12..19f5cd4 100644
--- a/crates/disktree-app/src/tests.rs
+++ b/crates/disktree-app/src/tests.rs
@@ -1014,6 +1014,51 @@ fn the_help_overlay_opens_and_closes(cx: &mut TestAppContext) {
assert!(!read(&view, cx, |app| app.show_help));
}
+#[gpui_kit::test]
+fn the_help_overlay_closes_by_button_and_from_outside_it(
+ cx: &mut TestAppContext,
+) {
+ cx.update(gpui_omarchy::init);
+ let temp = fixture();
+ let (view, cx) = view_over(temp.path(), cx);
+ draw(cx);
+ let drawn =
+ read(&view, cx, |app| (app.crumbs.clone(), app.selected.clone()));
+
+ press(cx, "?");
+ draw(cx);
+ assert!(read(&view, cx, |app| app.show_help));
+ // A press on the card is the card's own.
+ let card = cx.debug_bounds("help-card").expect("the key list");
+ cx.simulate_click(card.center(), gpui_kit::Modifiers::none());
+ draw(cx);
+ assert!(read(&view, cx, |app| app.show_help));
+ // One beside it closes the page, and the keys are the treemap's again.
+ let page = cx.debug_bounds("help").expect("the page");
+ let outside = Point::new(page.origin.x + px(4.), page.origin.y + px(4.));
+ cx.simulate_click(outside, gpui_kit::Modifiers::none());
+ draw(cx);
+ assert!(!read(&view, cx, |app| app.show_help));
+ // Neither press reached the screen behind: the same directory is drawn.
+ assert_eq!(
+ read(&view, cx, |app| (app.crumbs.clone(), app.selected.clone())),
+ drawn
+ );
+
+ // The way out is a button as well as a key.
+ press(cx, "?");
+ draw(cx);
+ assert!(read(&view, cx, |app| app.show_help));
+ let close = cx.debug_bounds("help-close").expect("Close");
+ cx.simulate_click(close.center(), gpui_kit::Modifiers::none());
+ draw(cx);
+ assert!(!read(&view, cx, |app| app.show_help));
+ press(cx, "?");
+ assert!(read(&view, cx, |app| app.show_help));
+ press(cx, "escape");
+ assert!(!read(&view, cx, |app| app.show_help));
+}
+
#[gpui_kit::test]
fn the_volume_picker_opens_moves_and_closes(cx: &mut TestAppContext) {
cx.update(gpui_omarchy::init);
diff --git a/crates/disktree-app/src/views.rs b/crates/disktree-app/src/views.rs
index 08c8952..3e9006c 100644
--- a/crates/disktree-app/src/views.rs
+++ b/crates/disktree-app/src/views.rs
@@ -332,6 +332,84 @@ fn centred_popup(
)
}
+/// A page over the dimmed window: the keys, for one. A press outside the
+/// card closes it, as Escape does; one on the card is the card's own, and
+/// nothing reaches the screen behind either way.
+fn modal(
+ id: &'static str,
+ theme: &Theme,
+ card: impl IntoElement,
+ close: fn(&mut Disktree, &mut Context<'_, Disktree>),
+ cx: &Context<'_, Disktree>,
+) -> Stateful
{
+ div()
+ .id(id)
+ .debug_selector(move || id.into())
+ .absolute()
+ .inset_0()
+ .flex()
+ .items_center()
+ .justify_center()
+ .bg(theme.background.opacity(0.86))
+ .on_any_mouse_down(cx.listener(
+ move |this, _: &MouseDownEvent, window, cx| {
+ cx.stop_propagation();
+ close(this, cx);
+ window.focus(&this.focus, cx);
+ },
+ ))
+ .child(
+ div()
+ .id(ElementId::Name(format!("{id}-card").into()))
+ .debug_selector(move || format!("{id}-card"))
+ .on_any_mouse_down(
+ |_: &MouseDownEvent, _: &mut Window, cx: &mut App| {
+ cx.stop_propagation();
+ },
+ )
+ .child(card),
+ )
+}
+
+/// A page's heading with the way out of it at the far end, for a hand on
+/// the mouse; Escape and a press outside do the same.
+fn page_header(
+ id: &'static str,
+ glyph: gpui_omarchy::IconName,
+ title: &'static str,
+ close: fn(&mut Disktree, &mut Context<'_, Disktree>),
+ cx: &Context<'_, Disktree>,
+) -> Div {
+ let theme = cx.omarchy();
+ div()
+ .flex()
+ .flex_row()
+ .items_center()
+ .gap(space::SM)
+ .child(
+ gpui_omarchy::icon(glyph)
+ .size(icon::MD)
+ .text_color(theme.accent),
+ )
+ .child(
+ div()
+ .text_size(text::TITLE)
+ .font_weight(FontWeight::BOLD)
+ .text_color(theme.bright)
+ .child(title),
+ )
+ .child(div().flex_1())
+ .child(
+ button(id, "Close", ButtonVariant::Secondary, cx)
+ .debug_selector(move || id.into())
+ .tab_stop(false)
+ .on_click(cx.listener(move |this, _, window, cx| {
+ close(this, cx);
+ window.focus(&this.focus, cx);
+ })),
+ )
+}
+
/// The one question disktree asks: a permanent deletion cannot be undone, so
/// it is an alert dialog that names what goes and what comes back. The trash is
/// reversible and needs no dialog.
@@ -3774,8 +3852,12 @@ const MODIFIER_OPEN: &str = if cfg!(target_os = "macos") {
"ctrl-o"
};
-fn help_overlay(app: &Disktree, cx: &gpui_kit::App) -> Div {
- let theme = cx.omarchy();
+fn help_overlay(app: &Disktree, cx: &Context<'_, Disktree>) -> Stateful
{
+ let theme = cx.omarchy().clone();
+ let close: fn(&mut Disktree, &mut Context<'_, Disktree>) = |this, cx| {
+ this.show_help = false;
+ cx.notify();
+ };
// Sentence case, and the tile a key acts on is always the one under the
// pointer if the pointer moved last, else the keyboard selection.
let rows = [
@@ -3859,54 +3941,32 @@ fn help_overlay(app: &Disktree, cx: &gpui_kit::App) -> Div {
);
}
- div()
- .absolute()
- .inset_0()
+ let card = div()
.flex()
- .items_center()
- .justify_center()
- .bg(theme.background.opacity(0.86))
+ .flex_col()
+ .gap(space::MD)
+ .w(size::HELP)
+ .p(space::XL)
+ .border_1()
+ .border_color(theme.border)
+ .bg(theme.surface)
+ .child(page_header(
+ "help-close",
+ gpui_omarchy::IconName::Keyboard,
+ "Keyboard and mouse",
+ close,
+ cx,
+ ))
+ .child(keys)
.child(
div()
- .flex()
- .flex_col()
- .gap(space::MD)
- .w(size::HELP)
- .p(space::XL)
- .border_1()
- .border_color(theme.border)
- .bg(theme.surface)
- .child(
- div()
- .flex()
- .flex_row()
- .items_center()
- .gap(space::SM)
- .child(
- gpui_omarchy::icon(
- gpui_omarchy::IconName::Keyboard,
- )
- .size(icon::MD)
- .text_color(theme.accent),
- )
- .child(
- div()
- .text_size(text::TITLE)
- .font_weight(FontWeight::BOLD)
- .text_color(theme.bright)
- .child("Keyboard and mouse"),
- ),
- )
- .child(keys)
- .child(
- div()
- .text_size(text::CAPTION)
- .text_color(theme.secondary)
- .child(format!(
- "? or esc closes \u{00b7} {} \u{00b7} {}",
- app.root_path.display(),
- app.options.metric.label()
- )),
- ),
- )
+ .text_size(text::CAPTION)
+ .text_color(theme.secondary)
+ .child(format!(
+ "?, esc or a click outside closes \u{00b7} {} \u{00b7} {}",
+ app.root_path.display(),
+ app.options.metric.label()
+ )),
+ );
+ modal("help", &theme, card, close, cx)
}