diff --git a/crates/rt-cef/src/float.rs b/crates/rt-cef/src/float.rs index c9dc51f..13908da 100644 --- a/crates/rt-cef/src/float.rs +++ b/crates/rt-cef/src/float.rs @@ -285,19 +285,25 @@ pub fn reposition() { shown = true; } } - // During a prompt the status bar keeps the keyboard, on purpose. - let prompting = shell::with(|s| { - matches!( + if !shown { + return; + } + // During a prompt the keys belong to the status bar (see + // `shell::focus_for_prompt`), so it gets them back rather than the tab. + let back = shell::with(|s| { + let prompting = matches!( s.engine.mode(), rt_core::Mode::Prompt | rt_core::Mode::YesNo - ) + ); + if prompting { + s.statusbar.clone() + } else { + s.tabs.current().map(|t| t.view.clone()) + } }) - .unwrap_or(false); - if shown - && !prompting - && let Some(tab) = shell::with(|s| s.tabs.current().map(|t| t.view.clone())).flatten() - { - crate::panes::focus_view(&tab); + .flatten(); + if let Some(view) = back { + crate::panes::focus_view(&view); } } diff --git a/crates/rt-e2e/tests/lua_events.rs b/crates/rt-e2e/tests/lua_events.rs index 2919eed..79cc984 100644 --- a/crates/rt-e2e/tests/lua_events.rs +++ b/crates/rt-e2e/tests/lua_events.rs @@ -198,6 +198,43 @@ end) }); } +/// A float that appears while riptide asks something leaves the keyboard +/// with the question: real keys, not the test channel, which skips focus. +#[test] +#[ignore = "starts a browser; run with ./task e2e"] +fn a_float_shown_during_a_question_leaves_it_the_keyboard() { + let b = Browser::launch() + .lua( + r#" +rt.command("ask-then-float", function() + rt.ui.input({ prompt = "Password", secret = true }, function(text) + rt.notify("typed " .. tostring(text)) + end) + rt.defer(300, function() rt.ui.float({ title = "Status", lines = { "working" } }) end) +end) +"#, + ) + .start("page.html"); + b.run("ask-then-float"); + b.wait_mode("prompt"); + b.wait_until("the float is placed", |s| { + s.floats.first().is_some_and(|f| f["placed"] == true) + }); + let xdotool = |args: &[&str]| { + let status = std::process::Command::new("xdotool") + .args(args) + .env("DISPLAY", format!(":{}", b.display())) + .status() + .expect("xdotool"); + assert!(status.success()); + }; + xdotool(&["type", "--delay", "20", "hunter2"]); + xdotool(&["key", "Return"]); + b.wait_until("the question got the keys", |s| { + s.message() == Some("typed hunter2") + }); +} + #[test] #[ignore = "starts a browser; run with ./task e2e"] fn panels_dock_beside_the_page_and_take_keys_when_focused() {