Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(gpui): preserve preview selection when the pointer leaves

Richie McIlroy2a326ca7f1d5
diff --git a/apps/desktop-gpui/src/editor_canvas.rs b/apps/desktop-gpui/src/editor_canvas.rs
index eaa364b54..14618f7be 100644
--- a/apps/desktop-gpui/src/editor_canvas.rs
+++ b/apps/desktop-gpui/src/editor_canvas.rs
@@ -970,6 +970,14 @@ impl EditorWindow {
let Some(drag) = self.canvas_drag.take() else {
return;
};
+ let hovered = self
+ .player_panel_bounds
+ .get()
+ .is_some_and(|bounds| bounds.contains(&window.mouse_position()));
+ self.set_player_panel_hovered(hovered, cx);
+ if !hovered {
+ self.hovered_canvas = None;
+ }
let config = self.project.clone();
self.history.resume(&config);
self.snap_guides.clear();
@@ -1249,6 +1257,16 @@ impl EditorWindow {
self.project_changed_live(cx);
}
+ pub(crate) fn set_player_panel_hovered(&mut self, hovered: bool, cx: &mut Context<Self>) {
+ if self.player_panel_hovered != hovered {
+ self.player_panel_hovered = hovered;
+ if !hovered && self.canvas_drag.is_none() {
+ self.hovered_canvas = None;
+ }
+ cx.notify();
+ }
+ }
+
fn set_canvas_hover(
&mut self,
element: CanvasSelection,
@@ -1286,7 +1304,9 @@ impl EditorWindow {
/// letterboxed frame's own space -- `CanvasElementsOverlay` is mounted
/// inside `size()` (`Player.tsx:636`), not the player pane.
pub(crate) fn render_canvas_overlay(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
- if !self.canvas_overlay_visible() {
+ if !self.canvas_overlay_visible()
+ || (!self.player_panel_hovered && self.canvas_drag.is_none())
+ {
return None;
}
let player = self.player_frame_rect.get()?;
diff --git a/apps/desktop-gpui/src/editor_window.rs b/apps/desktop-gpui/src/editor_window.rs
index 07360dd4a..9751fe35a 100644
--- a/apps/desktop-gpui/src/editor_window.rs
+++ b/apps/desktop-gpui/src/editor_window.rs
@@ -1558,6 +1558,8 @@ pub struct EditorWindow {
// -- The canvas display drag (E6) -----------------------------------------
/// The letterboxed frame rect the preview canvas last painted.
pub(crate) player_frame_rect: crate::editor_canvas::CanvasRect,
+ pub(crate) player_panel_bounds: ui::SliderTrack,
+ pub(crate) player_panel_hovered: bool,
/// `editorState.canvasSelection`.
pub(crate) canvas_selection: Option<crate::editor_canvas::CanvasSelection>,
/// `hovered` on `ElementBox` (`CanvasElementsOverlay.tsx:790`).
@@ -1885,6 +1887,8 @@ impl EditorWindow {
player_frame_rect,
canvas_selection: None,
hovered_canvas: None,
+ player_panel_bounds: ui::SliderTrack::default(),
+ player_panel_hovered: false,
canvas_drag: None,
canvas_drag_rect: None,
canvas_drag_camera_rect: None,
@@ -8659,11 +8663,21 @@ impl EditorWindow {
/// `PlayerContent`: one surface -- the actions toolbar, the stage, and the
/// transport, with no rule between them.
fn render_player(&self, cx: &mut Context<Self>) -> impl IntoElement {
+ let panel_bounds = self.player_panel_bounds.clone();
div()
+ .relative()
.flex()
.flex_col()
.flex_1()
.min_h_0()
+ .child(
+ gpui::canvas(
+ move |bounds, _, _| panel_bounds.set(Some(bounds)),
+ |_, _, _, _| {},
+ )
+ .absolute()
+ .inset_0(),
+ )
.child(
self.toolbar.clone().cached(
StyleRefinement::default()
@@ -10216,9 +10230,36 @@ impl Render for EditorWindow {
.child({
let move_editor = cx.entity().downgrade();
let up_editor = cx.entity().downgrade();
+ let hover_editor = cx.entity().downgrade();
+ let exit_editor = cx.entity().downgrade();
gpui::canvas(
|_bounds, _window, _cx| (),
move |_bounds, (), window, _cx| {
+ let editor = hover_editor.clone();
+ window.on_mouse_event(move |event: &MouseMoveEvent, phase, _, cx| {
+ if phase != gpui::DispatchPhase::Capture {
+ return;
+ }
+ editor
+ .update(cx, |this, cx| {
+ let hovered = this
+ .player_panel_bounds
+ .get()
+ .is_some_and(|bounds| bounds.contains(&event.position));
+ this.set_player_panel_hovered(hovered, cx);
+ })
+ .ok();
+ });
+ let editor = exit_editor.clone();
+ window.on_mouse_event(move |_: &gpui::MouseExitEvent, phase, _, cx| {
+ if phase == gpui::DispatchPhase::Capture {
+ editor
+ .update(cx, |this, cx| {
+ this.set_player_panel_hovered(false, cx);
+ })
+ .ok();
+ }
+ });
let editor = move_editor.clone();
window.on_mouse_event(move |event: &MouseMoveEvent, phase, window, cx| {
if phase != gpui::DispatchPhase::Bubble {