Skip to content

Commit 2b5b90f

Browse files
authored
Merge pull request #680 from multiplex55/codex/fix-removal-logic-in-dashboard-editor
Fix dashboard editor slot removal handling
2 parents af55d31 + 6ea6994 commit 2b5b90f

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

src/gui/dashboard_editor_dialog.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ impl DashboardEditorDialog {
243243

244244
ui.separator();
245245
let mut confirm_remove = None;
246+
let mut removed_once = false;
246247
if let Some(idx) = self.confirm_remove_slot {
247248
if let Some(slot) = self.config.slots.get(idx) {
248249
let label = Self::slot_label(slot);
@@ -278,7 +279,7 @@ impl DashboardEditorDialog {
278279
while idx < self.config.slots.len() {
279280
let original_slot = self.config.slots[idx].clone();
280281
let mut slot = original_slot.clone();
281-
let removed = confirm_remove == Some(idx);
282+
let removed = !removed_once && confirm_remove == Some(idx);
282283
let mut edited = false;
283284
let mut swapped = false;
284285
ui.push_id(idx, |ui| {
@@ -462,6 +463,9 @@ impl DashboardEditorDialog {
462463
});
463464
if removed {
464465
self.config.slots.remove(idx);
466+
removed_once = true;
467+
self.confirm_remove_slot = None;
468+
confirm_remove = None;
465469
if let Some(sel) = self.selected_slot {
466470
if sel >= idx && !self.config.slots.is_empty() {
467471
let next =
@@ -480,6 +484,7 @@ impl DashboardEditorDialog {
480484
}
481485
self.ensure_selected_slot();
482486
self.ensure_swap_anchor();
487+
idx += 1;
483488
} else if swapped {
484489
idx += 1;
485490
} else if edited && slot != original_slot {

src/window_manager.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ pub fn clear_mock_mouse_position() {
2525
}
2626
}
2727

28+
#[cfg_attr(not(test), allow(dead_code))]
29+
pub fn mock_mouse_position_is_set() -> bool {
30+
if let Ok(guard) = MOCK_MOUSE_POSITION.lock() {
31+
guard.is_some()
32+
} else {
33+
tracing::error!("failed to lock MOCK_MOUSE_POSITION");
34+
false
35+
}
36+
}
37+
2838
#[cfg_attr(not(test), allow(dead_code))]
2939
pub fn virtual_key_from_string(key: &str) -> Option<u32> {
3040
match key.to_uppercase().as_str() {

tests/window_manager.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,22 @@ use multi_launcher::window_manager::{
22
set_mock_mouse_position,
33
clear_mock_mouse_position,
44
current_mouse_position,
5+
mock_mouse_position_is_set,
56
virtual_key_from_string,
67
MOCK_MOUSE_LOCK,
78
};
89

910
#[test]
1011
fn mock_mouse_position_override_and_clear() {
1112
let _lock = MOCK_MOUSE_LOCK.lock().unwrap();
12-
// Capture the real position before mocking
13-
let real_pos = current_mouse_position();
14-
1513
// Set a custom mouse position and confirm it is returned
1614
set_mock_mouse_position(Some((10.0, 20.0)));
15+
assert!(mock_mouse_position_is_set());
1716
assert_eq!(current_mouse_position(), Some((10.0, 20.0)));
1817

19-
// Clear the mock and ensure the original position is restored
18+
// Clear the mock and ensure the mock state is cleared
2019
clear_mock_mouse_position();
21-
assert_eq!(current_mouse_position(), real_pos);
20+
assert!(!mock_mouse_position_is_set());
2221
}
2322

2423
#[test]
@@ -34,4 +33,3 @@ fn virtual_key_from_string_cases() {
3433
assert_eq!(virtual_key_from_string(input), expected, "input: {input}");
3534
}
3635
}
37-

0 commit comments

Comments
 (0)