fix(discovery): prioritize version popup input
This commit is contained in:
1 parent
2aa45fe15a
commit
b10e88c304
2 files changed
+64
-21
No files matched your search
@@ -338,6 +338,49 @@ fn project_page_navigation_is_bounded_and_can_go_back() {
|
||||
assert!(!state.project_page_open());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn version_popup_owns_navigation_over_a_project_page() {
|
||||
let project = DiscoveryProject {
|
||||
id: "project".to_owned(),
|
||||
slug: "project".to_owned(),
|
||||
title: "Project".to_owned(),
|
||||
description: String::new(),
|
||||
downloads: 0,
|
||||
icon_url: None,
|
||||
icon_bytes: None,
|
||||
};
|
||||
let mut state = DiscoveryState::new(ContentKind::Mod);
|
||||
state.list.entries.push(project_entry(project, None));
|
||||
state.list.list_state.selected = Some(0);
|
||||
state.project_page = Some(ProjectPageState {
|
||||
request_id: 1,
|
||||
project_id: "project".to_owned(),
|
||||
title: "Project".to_owned(),
|
||||
document: None,
|
||||
error: None,
|
||||
scroll: 0,
|
||||
max_scroll: 20,
|
||||
});
|
||||
let request = state.begin_versions().unwrap();
|
||||
DiscoveryState::push_action_result(
|
||||
&request.pending,
|
||||
DiscoveryActionResult::Versions {
|
||||
request_id: request.request_id,
|
||||
project_id: request.project_id,
|
||||
result: Ok(vec![version("1.0.0"), version("2.0.0")]),
|
||||
},
|
||||
);
|
||||
state.drain_pending();
|
||||
|
||||
handle_key(
|
||||
&KeyEvent::new(KeyCode::Char('j'), KeyModifiers::NONE),
|
||||
&mut state,
|
||||
);
|
||||
|
||||
assert_eq!(state.version_popup.as_ref().unwrap().selected, 1);
|
||||
assert_eq!(state.project_page.as_ref().unwrap().scroll, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn confirmation_can_return_to_version_selection() {
|
||||
let project = DiscoveryProject {
|
||||
|
||||
@@ -869,27 +869,6 @@ impl DiscoveryState {
|
||||
}
|
||||
|
||||
pub fn handle_key(key_event: &KeyEvent, state: &mut DiscoveryState) -> bool {
|
||||
if let Some(page) = state.project_page.as_mut() {
|
||||
match key_event.code {
|
||||
KeyCode::Esc | KeyCode::Left | KeyCode::Char('h') => state.project_page = None,
|
||||
KeyCode::Char('j') | KeyCode::Down => {
|
||||
page.scroll = page.scroll.saturating_add(1).min(page.max_scroll);
|
||||
}
|
||||
KeyCode::Char('k') | KeyCode::Up => {
|
||||
page.scroll = page.scroll.saturating_sub(1);
|
||||
}
|
||||
KeyCode::PageDown | KeyCode::Char('d') => {
|
||||
page.scroll = page.scroll.saturating_add(10).min(page.max_scroll);
|
||||
}
|
||||
KeyCode::PageUp | KeyCode::Char('u') => {
|
||||
page.scroll = page.scroll.saturating_sub(10);
|
||||
}
|
||||
KeyCode::Char('g') | KeyCode::Home => page.scroll = 0,
|
||||
KeyCode::Char('G') | KeyCode::End => page.scroll = page.max_scroll,
|
||||
_ => {}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if let Some(popup) = state.version_popup.as_mut() {
|
||||
if popup.confirming
|
||||
&& matches!(key_event.code, KeyCode::Left | KeyCode::Char('h'))
|
||||
@@ -917,6 +896,27 @@ pub fn handle_key(key_event: &KeyEvent, state: &mut DiscoveryState) -> bool {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if let Some(page) = state.project_page.as_mut() {
|
||||
match key_event.code {
|
||||
KeyCode::Esc | KeyCode::Left | KeyCode::Char('h') => state.project_page = None,
|
||||
KeyCode::Char('j') | KeyCode::Down => {
|
||||
page.scroll = page.scroll.saturating_add(1).min(page.max_scroll);
|
||||
}
|
||||
KeyCode::Char('k') | KeyCode::Up => {
|
||||
page.scroll = page.scroll.saturating_sub(1);
|
||||
}
|
||||
KeyCode::PageDown | KeyCode::Char('d') => {
|
||||
page.scroll = page.scroll.saturating_add(10).min(page.max_scroll);
|
||||
}
|
||||
KeyCode::PageUp | KeyCode::Char('u') => {
|
||||
page.scroll = page.scroll.saturating_sub(10);
|
||||
}
|
||||
KeyCode::Char('g') | KeyCode::Home => page.scroll = 0,
|
||||
KeyCode::Char('G') | KeyCode::End => page.scroll = page.max_scroll,
|
||||
_ => {}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if state.search.active {
|
||||
let previous_query = state.search.query.clone();
|
||||
match key_event.code {
|
||||
|
||||
Reference in new issue
Block a user