Skip to content

Remove focus on input when jumping back#184

Merged
Rigellute merged 1 commit into
Rigellute:masterfrom
nilsrauch:no-input-focus-on-back
Dec 23, 2019
Merged

Remove focus on input when jumping back#184
Rigellute merged 1 commit into
Rigellute:masterfrom
nilsrauch:no-input-focus-on-back

Conversation

@nilsrauch
Copy link
Copy Markdown
Contributor

This is fixing #174

First of all I wanted to say that I'm pretty new to Rust so if you notice anything and have tips for me please feel free to share them with me :)

Also I realized that if the first action is to use the input field (thus the second route in the navigation_stack being a route with the id Search) the Home route will not be shown on navigating back because the second route will be popped in the match I've added and the is_none() check will break after...

I didn't know how to prevent this effectively without slaughtering the code. So any ideas would be really appreciated.

@stevensonmt
Copy link
Copy Markdown

How about this:

let mut pop_result = app.pop_navigation_stack();
    match &pop_result {
        Some(route) => {
            pop_result = match route.id {
                RouteId::Search => app.pop_navigation_stack(),
                _ => pop_result
            }
        },
        None => {}
    }
if pop_result.is_none() {
    break; // Exit application
}

becomes this:

let pop_result = { match app.pop_navigation_stack() {
    Some(RouteId::Search) => app.pop_navigation_stack(),
    Some(x) => Some(x),
    None => None
};

if pop_result.is_none() {
    break // Exit application
}

@nilsrauch
Copy link
Copy Markdown
Contributor Author

Yeah i see, makes it definitely more compact and readable. Will change it as soon as i get to it

@nilsrauch
Copy link
Copy Markdown
Contributor Author

So I've tried your solution but it didn't quite add up. Just because on the first pop_navigation_stack call it returns an Option<Route> which we can't match on Some(RouteId::Search). And unwrapping the Option would result in a panic on the last occurence.
I did like the idea of just one assignement though so I've still refactored it a bit. Let me know what you think

@stevensonmt
Copy link
Copy Markdown

stevensonmt commented Dec 4, 2019

My apologies for not reading the original more closely. You could have done something like this to fix it:

let pop_result = { match app.pop_navigation_stack() {
    Some(x) if x.id == RouteId::Search  => app.pop_navigation_stack(),
    Some(x) => Some(x),
    None => None
};

if pop_result.is_none() {
    break // Exit application
}

Example: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=c0de3c73abe69f1ee0f97bcd3104c4f4

@nilsrauch nilsrauch force-pushed the no-input-focus-on-back branch from fda2539 to bd40482 Compare December 6, 2019 21:38
@nilsrauch
Copy link
Copy Markdown
Contributor Author

No need to apologize. Thanks for the help, didn't know about the guard clause inside a match arm. Tell me if somethings still not right. I've also just rebased and compressed to one commit

Copy link
Copy Markdown
Owner

@Rigellute Rigellute left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay in respoding @TheWalkingLeek.

Good work! Thank you for the contribution 👍

@Rigellute Rigellute merged commit 8aad1c1 into Rigellute:master Dec 23, 2019
@Rigellute
Copy link
Copy Markdown
Owner

@all-contributors please add @TheWalkingLeek for code

@allcontributors
Copy link
Copy Markdown
Contributor

@Rigellute

I've put up a pull request to add @TheWalkingLeek! 🎉

nighi pushed a commit to nighi/spotify-tui that referenced this pull request Jul 11, 2025
…n-back

Remove focus on input when jumping back
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants