Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(desktop-gpui): restore shortcuts after preview clicks

Aditya Garud31ce9af9b006
diff --git a/apps/desktop-gpui/Cargo.lock b/apps/desktop-gpui/Cargo.lock
index 949e7bbb5..4556ee85d 100644
--- a/apps/desktop-gpui/Cargo.lock
+++ b/apps/desktop-gpui/Cargo.lock
@@ -2546,6 +2546,15 @@ dependencies = [
"unicode-segmentation",
]
+[[package]]
+name = "convert_case"
+version = "0.11.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "affbf0190ed2caf063e3def54ff444b449371d55c58e513a95ab98eca50adb49"
+dependencies = [
+ "unicode-segmentation",
+]
+
[[package]]
name = "cookie"
version = "0.18.2"
@@ -4310,7 +4319,7 @@ dependencies = [
"num-traits",
"ordered-channel",
"pbr",
- "quick-error",
+ "quick-error 2.0.1",
"resize",
"rgb",
"wild",
@@ -4567,6 +4576,7 @@ dependencies = [
"anyhow",
"async-channel",
"async-task",
+ "backtrace",
"bindgen 0.71.1",
"bitflags 2.13.1",
"block",
@@ -4610,6 +4620,7 @@ dependencies = [
"pollster 0.4.0",
"postage",
"profiling",
+ "proptest",
"rand 0.9.5",
"raw-window-handle",
"refineable",
@@ -5463,7 +5474,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "525e9ff3e1a4be2fbea1fdf0e98686a6d98b4d8f937e1bf7402245af1909e8c3"
dependencies = [
"byteorder-lite",
- "quick-error",
+ "quick-error 2.0.1",
]
[[package]]
@@ -8370,6 +8381,36 @@ dependencies = [
"syn 2.0.119",
]
+[[package]]
+name = "proptest"
+version = "1.10.0"
+source = "git+https://github.com/proptest-rs/proptest?rev=3dca198a8fef1b32e3a66f1e1897c955b4dc5b5b#3dca198a8fef1b32e3a66f1e1897c955b4dc5b5b"
+dependencies = [
+ "bit-set 0.8.0",
+ "bit-vec 0.8.0",
+ "bitflags 2.13.1",
+ "num-traits",
+ "proptest-macro",
+ "rand 0.9.5",
+ "rand_chacha 0.9.0",
+ "rand_xorshift",
+ "regex-syntax",
+ "rusty-fork",
+ "tempfile",
+ "unarray",
+]
+
+[[package]]
+name = "proptest-macro"
+version = "0.5.0"
+source = "git+https://github.com/proptest-rs/proptest?rev=3dca198a8fef1b32e3a66f1e1897c955b4dc5b5b#3dca198a8fef1b32e3a66f1e1897c955b4dc5b5b"
+dependencies = [
+ "convert_case 0.11.0",
+ "proc-macro2",
+ "quote",
+ "syn 2.0.119",
+]
+
[[package]]
name = "psl-types"
version = "2.0.11"
@@ -8434,6 +8475,12 @@ dependencies = [
"bytemuck",
]
+[[package]]
+name = "quick-error"
+version = "1.2.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
+
[[package]]
name = "quick-error"
version = "2.0.1"
@@ -8662,6 +8709,15 @@ dependencies = [
"rand_core 0.10.1",
]
+[[package]]
+name = "rand_xorshift"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "513962919efc330f829edb2535844d1b912b0fbe2ca165d613e4e8788bb05a5a"
+dependencies = [
+ "rand_core 0.9.5",
+]
+
[[package]]
name = "range-alloc"
version = "0.1.5"
@@ -8718,7 +8774,7 @@ dependencies = [
"avif-serialize",
"imgref",
"loop9",
- "quick-error",
+ "quick-error 2.0.1",
"rav1e",
"rayon",
"rgb",
@@ -9312,6 +9368,18 @@ version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
+[[package]]
+name = "rusty-fork"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cc6bf79ff24e648f6da1f8d1f011e9cac26491b619e6b9280f2b47f1774e6ee2"
+dependencies = [
+ "fnv",
+ "quick-error 1.2.3",
+ "tempfile",
+ "wait-timeout",
+]
+
[[package]]
name = "rustybuzz"
version = "0.14.1"
@@ -10949,7 +11017,7 @@ dependencies = [
"fax",
"flate2",
"half",
- "quick-error",
+ "quick-error 2.0.1",
"weezl",
"zune-jpeg 0.5.15",
]
@@ -11518,6 +11586,12 @@ dependencies = [
"libc",
]
+[[package]]
+name = "unarray"
+version = "0.1.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94"
+
[[package]]
name = "unic-char-property"
version = "0.9.0"
@@ -11954,6 +12028,15 @@ dependencies = [
"libc",
]
+[[package]]
+name = "wait-timeout"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "09ac3b126d3914f9849036f826e054cbabdc8519970b8998ddaf3b5bd3c65f11"
+dependencies = [
+ "libc",
+]
+
[[package]]
name = "waker-fn"
version = "1.2.0"
diff --git a/apps/desktop-gpui/Cargo.toml b/apps/desktop-gpui/Cargo.toml
index f496ed30e..f14782fd8 100644
--- a/apps/desktop-gpui/Cargo.toml
+++ b/apps/desktop-gpui/Cargo.toml
@@ -169,6 +169,7 @@ cc = "1.4"
tauri-winres = "0.3.5"
[dev-dependencies]
+gpui = { git = "https://github.com/wingleeio/zed", rev = "5d1f83d9f27a19bec1fb241dc33b42238af9cf8d", features = ["test-support"] }
# The editor smoke (`tests/editor_frame0.rs`) drives `EditorInstance`, whose
# decoders, renderer and preview tasks are all tokio-spawned -- a current-thread
# runtime would deadlock the moment the test thread blocks on a frame. Kept in
diff --git a/apps/desktop-gpui/src/editor_window.rs b/apps/desktop-gpui/src/editor_window.rs
index d19e1cd05..79cf6bb42 100644
--- a/apps/desktop-gpui/src/editor_window.rs
+++ b/apps/desktop-gpui/src/editor_window.rs
@@ -9853,6 +9853,7 @@ impl EditorWindow {
/// the sprite atlas.
fn render_preview_canvas(&self, cx: &mut Context<Self>) -> impl IntoElement {
let theme = self.theme;
+ let editor = cx.entity().downgrade();
let body = match (&self.state, self.latest_frame.is_some()) {
(LoadState::Failed(message), _) => self.render_error_state(message).into_any_element(),
(_, true) => loading::reveal(
@@ -9866,11 +9867,32 @@ impl EditorWindow {
};
div()
+ .debug_selector(|| "editor-preview-canvas".into())
.relative()
.flex_1()
.min_h_0()
.overflow_hidden()
.bg(Hsla::from(theme.editor.card))
+ .child(
+ gpui::canvas(
+ |bounds, _, _| bounds,
+ move |_, bounds, window, _| {
+ let editor = editor.clone();
+ window.on_mouse_event(move |event: &MouseDownEvent, phase, window, cx| {
+ if phase == gpui::DispatchPhase::Capture
+ && event.button == MouseButton::Left
+ && bounds.contains(&event.position)
+ {
+ let _ = editor.update(cx, |this, cx| {
+ this.focus_root(window, cx);
+ });
+ }
+ });
+ },
+ )
+ .absolute()
+ .inset_0(),
+ )
.child(body)
// `CanvasElementsOverlay` + `SnapGuidesOverlay`
// (`Player.tsx:636-643`), both mounted inside the letterbox
@@ -12540,6 +12562,32 @@ mod tests {
}
}
+ #[gpui::test]
+ fn preview_click_returns_focus_to_the_editor(cx: &mut gpui::TestAppContext) {
+ let project = tempfile::tempdir().unwrap();
+ let project_path = project.path().to_path_buf();
+ let (editor, cx) = cx
+ .add_window_view(move |window, cx| EditorWindow::new(project_path.clone(), window, cx));
+ let (input_focus, editor_focus) = editor.read_with(cx, |editor, cx| {
+ (
+ editor.name_input.read(cx).focus_handle(),
+ editor.focus.clone(),
+ )
+ });
+
+ cx.update(|window, cx| window.focus(&input_focus, cx));
+ cx.update(|window, _| assert!(input_focus.is_focused(window)));
+
+ let preview = cx.debug_bounds("editor-preview-canvas").unwrap();
+ cx.simulate_mouse_move(preview.center(), None, gpui::Modifiers::default());
+ cx.simulate_click(preview.center(), gpui::Modifiers::default());
+
+ cx.update(|window, _| {
+ assert!(!input_focus.is_focused(window));
+ assert!(editor_focus.is_focused(window));
+ });
+ }
+
/// `default_editor_preview_resolution()` is asserted to be 1248x702 in the
/// Tauri app itself (`lib.rs:192-194`); the render size of a display
/// recording follows from it.