diff --git a/src/gui/dashboard_editor_dialog.rs b/src/gui/dashboard_editor_dialog.rs index 49a0043f..484973fa 100644 --- a/src/gui/dashboard_editor_dialog.rs +++ b/src/gui/dashboard_editor_dialog.rs @@ -243,6 +243,7 @@ impl DashboardEditorDialog { ui.separator(); let mut confirm_remove = None; + let mut removed_once = false; if let Some(idx) = self.confirm_remove_slot { if let Some(slot) = self.config.slots.get(idx) { let label = Self::slot_label(slot); @@ -278,7 +279,7 @@ impl DashboardEditorDialog { while idx < self.config.slots.len() { let original_slot = self.config.slots[idx].clone(); let mut slot = original_slot.clone(); - let removed = confirm_remove == Some(idx); + let removed = !removed_once && confirm_remove == Some(idx); let mut edited = false; let mut swapped = false; ui.push_id(idx, |ui| { @@ -462,6 +463,9 @@ impl DashboardEditorDialog { }); if removed { self.config.slots.remove(idx); + removed_once = true; + self.confirm_remove_slot = None; + confirm_remove = None; if let Some(sel) = self.selected_slot { if sel >= idx && !self.config.slots.is_empty() { let next = @@ -480,6 +484,7 @@ impl DashboardEditorDialog { } self.ensure_selected_slot(); self.ensure_swap_anchor(); + idx += 1; } else if swapped { idx += 1; } else if edited && slot != original_slot { diff --git a/src/window_manager.rs b/src/window_manager.rs index 5fb908de..5cda10e7 100644 --- a/src/window_manager.rs +++ b/src/window_manager.rs @@ -25,6 +25,16 @@ pub fn clear_mock_mouse_position() { } } +#[cfg_attr(not(test), allow(dead_code))] +pub fn mock_mouse_position_is_set() -> bool { + if let Ok(guard) = MOCK_MOUSE_POSITION.lock() { + guard.is_some() + } else { + tracing::error!("failed to lock MOCK_MOUSE_POSITION"); + false + } +} + #[cfg_attr(not(test), allow(dead_code))] pub fn virtual_key_from_string(key: &str) -> Option { match key.to_uppercase().as_str() { diff --git a/tests/window_manager.rs b/tests/window_manager.rs index ae6b177c..ae5eb948 100644 --- a/tests/window_manager.rs +++ b/tests/window_manager.rs @@ -2,6 +2,7 @@ use multi_launcher::window_manager::{ set_mock_mouse_position, clear_mock_mouse_position, current_mouse_position, + mock_mouse_position_is_set, virtual_key_from_string, MOCK_MOUSE_LOCK, }; @@ -9,16 +10,14 @@ use multi_launcher::window_manager::{ #[test] fn mock_mouse_position_override_and_clear() { let _lock = MOCK_MOUSE_LOCK.lock().unwrap(); - // Capture the real position before mocking - let real_pos = current_mouse_position(); - // Set a custom mouse position and confirm it is returned set_mock_mouse_position(Some((10.0, 20.0))); + assert!(mock_mouse_position_is_set()); assert_eq!(current_mouse_position(), Some((10.0, 20.0))); - // Clear the mock and ensure the original position is restored + // Clear the mock and ensure the mock state is cleared clear_mock_mouse_position(); - assert_eq!(current_mouse_position(), real_pos); + assert!(!mock_mouse_position_is_set()); } #[test] @@ -34,4 +33,3 @@ fn virtual_key_from_string_cases() { assert_eq!(virtual_key_from_string(input), expected, "input: {input}"); } } -