fix(tui): guard contextual content actions
This commit is contained in:
1 parent
59707b77d2
commit
70286ed9b8
7 files changed
+114
-2
No files matched your search
+24
-1
@@ -433,6 +433,7 @@ impl App {
|
||||
}
|
||||
if key_event.code == KeyCode::Char('v')
|
||||
&& !self.world_datapacks_state.search.active
|
||||
&& self.world_datapacks_state.selected_has_provider_project()
|
||||
{
|
||||
self.spawn_installed_versions();
|
||||
return Ok(());
|
||||
@@ -505,7 +506,10 @@ impl App {
|
||||
self.spawn_bulk_content_updates();
|
||||
return Ok(());
|
||||
}
|
||||
if key_event.code == KeyCode::Char('v') && !state.search.active {
|
||||
if key_event.code == KeyCode::Char('v')
|
||||
&& !state.search.active
|
||||
&& state.selected_has_provider_project()
|
||||
{
|
||||
self.spawn_installed_versions();
|
||||
return Ok(());
|
||||
}
|
||||
@@ -542,6 +546,11 @@ impl App {
|
||||
}
|
||||
|
||||
if self.focused == FocusedArea::Settings {
|
||||
let dismissed_input = key_event.code == KeyCode::Esc
|
||||
&& matches!(
|
||||
&self.settings_state.add_mode,
|
||||
widgets::settings::AddMode::ProfileName(_)
|
||||
);
|
||||
match widgets::settings::handle_key(
|
||||
&key_event,
|
||||
&mut self.settings_state,
|
||||
@@ -629,6 +638,9 @@ impl App {
|
||||
}
|
||||
widgets::settings::SettingsAction::None => {}
|
||||
}
|
||||
if dismissed_input {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
match self.focused {
|
||||
@@ -683,6 +695,17 @@ impl App {
|
||||
// global keybindings (uppercase = area switch, lowercase = action)
|
||||
match key_event.code {
|
||||
KeyCode::Char('q') => self.exit = true,
|
||||
KeyCode::Esc
|
||||
if matches!(
|
||||
self.focused,
|
||||
FocusedArea::Content
|
||||
| FocusedArea::Account
|
||||
| FocusedArea::Settings
|
||||
| FocusedArea::Overview
|
||||
) =>
|
||||
{
|
||||
self.focused = FocusedArea::Instances;
|
||||
}
|
||||
KeyCode::Char('I') => self.focused = FocusedArea::Instances,
|
||||
KeyCode::Char('C') => self.focused = FocusedArea::Content,
|
||||
KeyCode::Char('A') => self.focused = FocusedArea::Account,
|
||||
|
||||
@@ -32,6 +32,50 @@ fn global_navigation_returns_from_log_overlay() {
|
||||
assert!(ui.app.exit);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn escape_returns_through_nested_sections() {
|
||||
let mut ui = UiHarness::new();
|
||||
|
||||
for focused in [
|
||||
FocusedArea::Content,
|
||||
FocusedArea::Account,
|
||||
FocusedArea::Settings,
|
||||
] {
|
||||
ui.app.focused = focused;
|
||||
ui.key(KeyCode::Esc);
|
||||
assert_eq!(ui.app.focused, FocusedArea::Instances);
|
||||
}
|
||||
|
||||
ui.app.focused = FocusedArea::Content;
|
||||
ui.app.content_tab = ContentTab::Worlds;
|
||||
ui.app.open_world_datapacks = Some(("World".to_owned(), PathBuf::from("World")));
|
||||
ui.key(KeyCode::Esc);
|
||||
|
||||
assert_eq!(ui.app.focused, FocusedArea::Content);
|
||||
assert!(ui.app.open_world_datapacks.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unmatched_installed_content_has_no_version_action() {
|
||||
let mut ui = UiHarness::new();
|
||||
ui.add_instance("Unmatched");
|
||||
ui.app.focused = FocusedArea::Content;
|
||||
ui.app.content_tab = ContentTab::Mods;
|
||||
let path = ui
|
||||
.instance_path("Unmatched")
|
||||
.join("minecraft/mods/unknown.jar");
|
||||
std::fs::create_dir_all(path.parent().unwrap()).unwrap();
|
||||
std::fs::write(&path, []).unwrap();
|
||||
ui.app.mods_state.entries = vec![content_entry("Unknown mod", path)];
|
||||
ui.app.mods_state.list_state.selected = Some(0);
|
||||
|
||||
ui.draw();
|
||||
assert!(!ui.screen().contains("[v] versions"));
|
||||
|
||||
ui.key(KeyCode::Char('v'));
|
||||
assert!(ui.app.mods_discovery_state.version_popup.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn worlds_reserves_q_for_available_quick_launch() {
|
||||
let mut ui = UiHarness::new();
|
||||
|
||||
@@ -41,6 +41,24 @@ fn entry(name: &str) -> ContentEntry {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn selected_provider_project_tracks_the_filtered_selection() {
|
||||
let mut state = ContentListState {
|
||||
entries: vec![entry("Unmatched"), entry("Matched")],
|
||||
..Default::default()
|
||||
};
|
||||
state.entries[1].provider_project = Some(crate::instance::ProviderProject {
|
||||
provider: "modrinth".to_owned(),
|
||||
project_id: "matched".to_owned(),
|
||||
version_id: "version".to_owned(),
|
||||
});
|
||||
state.list_state.selected = Some(0);
|
||||
|
||||
assert!(!state.selected_has_provider_project());
|
||||
state.list_state.selected = Some(1);
|
||||
assert!(state.selected_has_provider_project());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn world_cards_preview_up_to_three_datapacks() {
|
||||
let lines = world_descriptions(&WorldDetails {
|
||||
|
||||
@@ -222,7 +222,12 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut A
|
||||
|
||||
let keybind_line = if focused == FocusedArea::Account {
|
||||
Some(super::popups::keybind_line_fitted(
|
||||
&[("⏎", " select"), ("a", " add"), ("d", " del")],
|
||||
&[
|
||||
("⏎", " select"),
|
||||
("a", " add"),
|
||||
("d", " del"),
|
||||
("Esc", " back"),
|
||||
],
|
||||
area.width.saturating_sub(2),
|
||||
))
|
||||
} else {
|
||||
|
||||
@@ -1125,6 +1125,11 @@ impl ContentListState {
|
||||
self.entries.get(*index)
|
||||
}
|
||||
|
||||
pub fn selected_has_provider_project(&self) -> bool {
|
||||
self.selected_entry()
|
||||
.is_some_and(|entry| entry.provider_project.is_some())
|
||||
}
|
||||
|
||||
fn restore_selected_file_stem(&mut self, file_stem: Option<&str>) {
|
||||
let filtered = self.filtered_indices();
|
||||
self.list_state.selected = file_stem
|
||||
|
||||
@@ -301,6 +301,15 @@ pub fn render(
|
||||
_ => worlds_state.entries.iter(),
|
||||
}
|
||||
.any(|entry| entry.title_suffix.as_deref() == Some("Update"));
|
||||
let can_change_version = match tab {
|
||||
ContentTab::Mods => mods_state.selected_has_provider_project(),
|
||||
ContentTab::ResourcePacks => resource_packs_state.selected_has_provider_project(),
|
||||
ContentTab::Shaders => shaders_state.selected_has_provider_project(),
|
||||
ContentTab::Worlds if open_world_datapacks.is_some() => {
|
||||
world_datapacks_state.selected_has_provider_project()
|
||||
}
|
||||
_ => false,
|
||||
};
|
||||
|
||||
// keybinds change depending on which tab is active and whether
|
||||
// the content panel or instances panel has focus
|
||||
@@ -428,6 +437,12 @@ pub fn render(
|
||||
if is_focused && mode == ContentMode::Installed && !has_updates {
|
||||
keybinds.retain(|(key, _)| *key != "u");
|
||||
}
|
||||
if is_focused && mode == ContentMode::Installed && !can_change_version {
|
||||
keybinds.retain(|(key, _)| *key != "v");
|
||||
}
|
||||
if is_focused && !keybinds.iter().any(|(key, _)| key.contains("Esc")) {
|
||||
keybinds.push(("Esc", " back"));
|
||||
}
|
||||
// The main panel footer stays on its border; lower-priority hints are omitted when narrow.
|
||||
block = block.title_bottom(crate::tui::widgets::popups::keybind_line_fitted(
|
||||
&keybinds,
|
||||
|
||||
@@ -218,12 +218,14 @@ pub fn render(
|
||||
("d", " del"),
|
||||
("j/k", " move"),
|
||||
("h/l", " tab"),
|
||||
("Esc", " back"),
|
||||
],
|
||||
SettingsPane::Info => &[
|
||||
("e", " inst"),
|
||||
("g", " global"),
|
||||
("d", " desk"),
|
||||
("h/l", " tab"),
|
||||
("Esc", " back"),
|
||||
],
|
||||
};
|
||||
Some(super::popups::keybind_line_fitted(
|
||||
|
||||
Reference in new issue
Block a user