diff --git a/crates/ui-egui/src/doc_windows.rs b/crates/ui-egui/src/doc_windows.rs index 9c65f48e24..216d3b65b9 100644 --- a/crates/ui-egui/src/doc_windows.rs +++ b/crates/ui-egui/src/doc_windows.rs @@ -335,6 +335,7 @@ fn show_windows(app: &mut VectorcraftApp, ui: &mut egui::Ui) { // Presentation Mode fits each floating window it shows to the main window: back in their // floating windows, those views fit their windows again. let presenting = presenting(app); + let restoring = !presenting && app.canvas.windows.presented.is_some(); if presenting { let is_floating = current.is_some_and(|k| floating(app, &k)); let shown = app.canvas.windows.presented.get_or_insert_default(); @@ -365,9 +366,15 @@ fn show_windows(app: &mut VectorcraftApp, ui: &mut egui::Ui) { return; } let raise = current.filter(|u| app.canvas.windows.current != Some(*u)); - app.canvas.windows.current = current; let ctx = ui.ctx().clone(); let os_windows = WindowHost::of(&ctx).viewports_available(); + if restoring && !os_windows && raise.is_some() { + // egui raises every reappearing area in this pass, preserving their old order. Repeat + // the current window's raise next frame, when the other windows no longer request it. + ctx.request_repaint(); + } else { + app.canvas.windows.current = current; + } // An OS window's place is in desktop points: the main window's own origin shifts it. let origin = if os_windows { ctx.input(|i| i.viewport().inner_rect.map(|r| r.min)).filter(|p| p.is_finite()).unwrap_or(egui::Pos2::ZERO).to_vec2() diff --git a/crates/ui-egui/src/doc_windows/tests.rs b/crates/ui-egui/src/doc_windows/tests.rs index 3e8ffbff5b..931813e14a 100644 --- a/crates/ui-egui/src/doc_windows/tests.rs +++ b/crates/ui-egui/src/doc_windows/tests.rs @@ -417,23 +417,36 @@ fn presentation_mode_shows_the_floating_current_document_in_the_main_window() { #[test] fn a_document_made_current_in_presentation_mode_comes_to_the_front_after_it() { - let mut app = app_with(2); - let ctx = crate::testing::ui_context(); - frame(&mut app, &ctx, vec![]); - app.run("window.arrange.floatAllInWindows", json!({})).unwrap(); - frame(&mut app, &ctx, vec![]); - frame(&mut app, &ctx, vec![]); - // Where the two windows overlap: document 1's title bar, over document 0's body. - let overlap = app.ui.floating[1].place.min + vec2(60.0, 10.0); - app.run("view.presentation", json!({})).unwrap(); - frame(&mut app, &ctx, vec![]); - app.run("document.activate", json!({"index": 0})).unwrap(); - frame(&mut app, &ctx, vec![]); - app.run("view.presentation", json!({})).unwrap(); - frame(&mut app, &ctx, vec![]); - frame(&mut app, &ctx, vec![]); - click(&mut app, &ctx, overlap); - assert_eq!(app.session.active_index(), Some(0), "document 0's window is in front where they overlap"); + for change_during_presentation in [false, true] { + let mut app = app_with(2); + let ctx = crate::testing::ui_context(); + frame(&mut app, &ctx, vec![]); + app.run("window.arrange.floatAllInWindows", json!({})).unwrap(); + frame(&mut app, &ctx, vec![]); + frame(&mut app, &ctx, vec![]); + // Where the two windows overlap: document 1's title bar, over document 0's body. + let overlap = app.ui.floating[1].place.min + vec2(60.0, 10.0); + // Cover both an unchanged current document and one chosen while the windows are hidden. + if !change_during_presentation { + app.run("document.activate", json!({"index": 0})).unwrap(); + frame(&mut app, &ctx, vec![]); + } + app.run("view.presentation", json!({})).unwrap(); + frame(&mut app, &ctx, vec![]); + if change_during_presentation { + app.run("document.activate", json!({"index": 0})).unwrap(); + frame(&mut app, &ctx, vec![]); + } + app.run("view.presentation", json!({})).unwrap(); + frame(&mut app, &ctx, vec![]); + frame(&mut app, &ctx, vec![]); + click(&mut app, &ctx, overlap); + assert_eq!( + app.session.active_index(), + Some(0), + "document 0's window is in front (changed during presentation: {change_during_presentation})" + ); + } } /// A stand-in for the window system of the documents' OS windows: it runs each one's frame and asks