Skip to content

misterdownloadmanager: The ultimate open-source, clean-room download manager written from scratch in pure Rust for Windows, Mac, and Linux

RSS feeds: the rule boxes keep the keyboard while you type (#353) (#381)

Ahmed Nefzaoui246c2e4b00e6
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7e88572e..2fdbfeb4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,7 @@ Each release's notes on GitHub come from its section here (`## [X.Y.Z]`, see
### Fixed
+- RSS feeds: the boxes on the **Download rules** tab (**Episodes**, **Must contain** and the others) keep the keyboard while you type, instead of losing it after each key ([#353](https://github.com/anefzaoui/misterdownloadmanager/issues/353)).
- A download refused by a site's bot check (Cloudflare's challenge) says so and how to get the file, instead of "the server answered 403 Forbidden" ([#376](https://github.com/anefzaoui/misterdownloadmanager/issues/376)).
- **Open folder** works on a torrent that is still downloading ([#354](https://github.com/anefzaoui/misterdownloadmanager/issues/354)).
- **Alt** and **F10** open the menu bar while a button or the list has the keyboard focus, not only when nothing does ([#328](https://github.com/anefzaoui/misterdownloadmanager/issues/328)).
diff --git a/ROADMAP.md b/ROADMAP.md
index 4bc7baef..387830d0 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -466,6 +466,8 @@ These ship in a later version, when they're ready.
### Bugs being looked into
+- 🔄 RSS feeds: the rule boxes losing the keyboard after each key
+ ([#353](https://github.com/anefzaoui/misterdownloadmanager/issues/353)): fix in review
- 🔄 Video progress at 100 % while still downloading, and long encoded strings as file names
([#344](https://github.com/anefzaoui/misterdownloadmanager/issues/344),
[#345](https://github.com/anefzaoui/misterdownloadmanager/issues/345)): fix in review
diff --git a/crates/app/src/rssdlg.rs b/crates/app/src/rssdlg.rs
index 44d7587b..1fd8d917 100644
--- a/crates/app/src/rssdlg.rs
+++ b/crates/app/src/rssdlg.rs
@@ -61,7 +61,11 @@ impl RssWindow {
store: &mut Store,
busy: &HashSet<u64>,
) -> Outcome<Act> {
- window(
+ // What the app must do goes out after the window's pass, with the window still open: a
+ // dialog's `Done` means it closed, and starts its next opening afresh, its text boxes
+ // included (#353: each key typed saved the rule and took the box's focus away).
+ let mut asked = None;
+ let out = window(
ctx,
"rss",
"RSS feeds",
@@ -90,7 +94,7 @@ impl RssWindow {
{
self.tab = i;
}
- let act = if self.tab == 0 {
+ asked = if self.tab == 0 {
self.feeds_page(ui, o, store, busy)
} else {
self.rules_page(ui, o, store)
@@ -105,14 +109,16 @@ impl RssWindow {
)
.clicked();
if close || winui::escape_pressed(ui) {
- Outcome::Closed
- } else if let Some(a) = act {
- Outcome::Done(a)
+ Outcome::<()>::Closed
} else {
Outcome::Open
}
},
- )
+ );
+ match out {
+ Outcome::Closed => Outcome::Closed,
+ _ => asked.map_or(Outcome::Open, Outcome::Done),
+ }
}
fn feeds_page(
@@ -787,6 +793,84 @@ impl RssWindow {
mod tests {
use super::*;
use crate::rss::Parsed;
+ use egui::{Event, Modifiers, PointerButton, Rect, vec2};
+ use std::cell::RefCell;
+ use std::rc::Rc;
+
+ /// A rule's text box, typed into as one sits at the keyboard: the window opened on Download
+ /// rules, the box clicked once, then `typed` a character per frame.
+ fn typed_into(y: f32, typed: &str) -> Rule {
+ let mut store = Store::default();
+ let id = store.new_id();
+ store.rules.push(Rule::new(id, "Rule"));
+ let mut dlg = RssWindow::new(&store, true);
+
+ // The dialog's window is rendered as eframe renders it: its own pass, its own input.
+ let events: Rc<RefCell<Vec<Event>>> = Rc::default();
+ {
+ let events = events.clone();
+ egui::Context::set_immediate_viewport_renderer(move |ctx, viewport| {
+ let input = egui::RawInput {
+ viewport_id: viewport.ids.this,
+ viewports: std::iter::once((viewport.ids.this, egui::ViewportInfo::default()))
+ .collect(),
+ screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(760.0, 560.0))),
+ events: std::mem::take(&mut *events.borrow_mut()),
+ ..Default::default()
+ };
+ let mut ui_cb = viewport.viewport_ui_cb;
+ let mut out = ctx.run_ui(input, |ui| ui_cb(ui));
+ out.textures_delta.clear();
+ });
+ }
+ let ctx = egui::Context::default();
+ ctx.set_embed_viewports(false);
+ let mut pass = |store: &mut Store, send: Vec<Event>| {
+ *events.borrow_mut() = send;
+ let mut out = ctx.run_ui(egui::RawInput::default(), |ui| {
+ let _ = dlg.show(ui.ctx(), store, &HashSet::new());
+ });
+ out.textures_delta.clear();
+ };
+ for _ in 0..3 {
+ pass(&mut store, Vec::new());
+ }
+ let caption = if crate::dialogs::drawn_captions() {
+ crate::winui::caption::CAPTION_H
+ } else {
+ 0.0
+ };
+ let at = pos2(500.0, caption + y + 11.0);
+ let button = |pressed| Event::PointerButton {
+ pos: at,
+ button: PointerButton::Primary,
+ pressed,
+ modifiers: Modifiers::default(),
+ };
+ pass(&mut store, vec![Event::PointerMoved(at)]);
+ pass(&mut store, vec![button(true)]);
+ pass(&mut store, vec![button(false)]);
+ pass(&mut store, Vec::new());
+ for c in typed.chars() {
+ pass(&mut store, vec![Event::Text(c.to_string())]);
+ pass(&mut store, Vec::new());
+ }
+ store.rules.remove(0)
+ }
+
+ /// #353: a key typed in a box of the rule editor saves the rule, and saving isn't closing:
+ /// the box keeps the keyboard, so the next key lands in it too.
+ #[test]
+ fn typing_in_the_episodes_box_keeps_its_focus() {
+ // A partly typed filter ("1" can be read, "1x" can't) as much as a whole one.
+ assert_eq!(typed_into(184.0, "1x2-").episodes, "1x2-");
+ }
+
+ #[test]
+ fn typing_in_the_words_boxes_keeps_their_focus() {
+ assert_eq!(typed_into(102.0, "linux").must, "linux");
+ assert_eq!(typed_into(130.0, "cam").must_not, "cam");
+ }
/// #321: removing a feed in the RSS feeds window (including the last one) updates the
/// selection for the rest of the frame instead of indexing `store.feeds` with the old row.