Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/gui/dashboard_editor_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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| {
Expand Down Expand Up @@ -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 =
Expand All @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions src/window_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32> {
match key.to_uppercase().as_str() {
Expand Down
10 changes: 4 additions & 6 deletions tests/window_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@ 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,
};

#[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]
Expand All @@ -34,4 +33,3 @@ fn virtual_key_from_string_cases() {
assert_eq!(virtual_key_from_string(input), expected, "input: {input}");
}
}