Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(desktop-gpui): key screenshot cards and rows by path too

Richie McIlroyfe6a82756da8
diff --git a/apps/desktop-gpui/src/main_window.rs b/apps/desktop-gpui/src/main_window.rs
index c9fd7b3b4..982952e6e 100644
--- a/apps/desktop-gpui/src/main_window.rs
+++ b/apps/desktop-gpui/src/main_window.rs
@@ -4549,14 +4549,11 @@ impl MainWindow {
}
}
(LibraryKind::Screenshots, Some(LibraryItems::Screenshots(rows))) => {
- for (index, row) in rows.iter().enumerate() {
+ for row in rows {
if !self.matches_search(&row.item.pretty_name) {
continue;
}
- cards.push(
- self.render_screenshot_card(index, row, cx)
- .into_any_element(),
- );
+ cards.push(self.render_screenshot_card(row, cx).into_any_element());
}
}
_ => {}
@@ -4868,16 +4865,15 @@ impl MainWindow {
fn render_screenshot_card(
&self,
- index: usize,
row: &LibraryRow<ScreenshotItem>,
cx: &mut Context<Self>,
) -> impl IntoElement {
let theme = self.theme;
let item = &row.item;
let png = item.path.clone();
- let actions = self.render_screenshot_card_actions(index, item, cx);
+ let actions = self.render_screenshot_card_actions(item, cx);
self.library_card(
- ("library-screenshot", index),
+ gpui::ElementId::Path(item.path.as_path().into()),
row.thumbnail.clone(),
"icons/image.svg",
item.pretty_name.clone(),
@@ -4894,7 +4890,6 @@ impl MainWindow {
fn render_screenshot_card_actions(
&self,
- index: usize,
item: &ScreenshotItem,
cx: &mut Context<Self>,
) -> gpui::Div {
@@ -4909,39 +4904,35 @@ impl MainWindow {
.px(px(8.))
.pb(px(6.))
.gap(px(4.))
- .child(
- self.library_action(("lib-ss-copy", index), "icons/copy.svg", {
- let png = png.clone();
- move |_, _, cx| {
- let copied = crate::platform::copy_image_to_clipboard(png.clone(), cx);
- cx.spawn(async move |_| {
- if let Err(error) = copied.await {
- tracing::warn!("copying screenshot failed: {error}");
- crate::platform::alert_dialog(
- tr::main::library::copy_screenshot_failed(),
- &error,
- );
- }
- })
- .detach();
- }
- }),
- )
+ .child(self.library_action("lib-ss-copy", "icons/copy.svg", {
+ let png = png.clone();
+ move |_, _, cx| {
+ let copied = crate::platform::copy_image_to_clipboard(png.clone(), cx);
+ cx.spawn(async move |_| {
+ if let Err(error) = copied.await {
+ tracing::warn!("copying screenshot failed: {error}");
+ crate::platform::alert_dialog(
+ tr::main::library::copy_screenshot_failed(),
+ &error,
+ );
+ }
+ })
+ .detach();
+ }
+ }))
.child(self.library_action(
- ("lib-ss-save", index),
+ "lib-ss-save",
"icons/download.svg",
cx.listener(move |this, _, window, cx| {
this.save_screenshot(png.clone(), name.clone(), window, cx);
}),
))
- .child(
- self.library_action(("lib-ss-open", index), "icons/folder.svg", {
- let bundle = bundle.clone();
- move |_, _, cx| library::reveal_path(&bundle, cx)
- }),
- )
+ .child(self.library_action("lib-ss-open", "icons/folder.svg", {
+ let bundle = bundle.clone();
+ move |_, _, cx| library::reveal_path(&bundle, cx)
+ }))
.child(self.library_action(
- ("lib-ss-delete", index),
+ "lib-ss-delete",
"icons/trash.svg",
cx.listener(move |this, _, window, cx| {
this.delete_library_screenshot(bundle.clone(), window, cx);
diff --git a/apps/desktop-gpui/src/settings_window.rs b/apps/desktop-gpui/src/settings_window.rs
index 8d82f051a..9e1ad5774 100644
--- a/apps/desktop-gpui/src/settings_window.rs
+++ b/apps/desktop-gpui/src/settings_window.rs
@@ -2511,7 +2511,7 @@ impl SettingsWindow {
let mut items = Vec::with_capacity(visible);
for (index, row) in indices.into_iter().map(|row| &rows[row]).enumerate() {
items.push(
- self.render_screenshot_row(index, row, index + 1 == visible, cx)
+ self.render_screenshot_row(row, index + 1 == visible, cx)
.into_any_element(),
);
}
@@ -2562,7 +2562,6 @@ impl SettingsWindow {
fn render_screenshot_row(
&self,
- index: usize,
row: &ScreenshotRow,
last: bool,
cx: &mut Context<Self>,
@@ -2614,7 +2613,7 @@ impl SettingsWindow {
.items_center()
.gap(px(8.))
.child(self.row_button(
- ("screenshot-copy", index),
+ "screenshot-copy",
"icons/copy.svg",
"Copy to clipboard",
false,
@@ -2634,7 +2633,7 @@ impl SettingsWindow {
},
))
.child(self.row_button(
- ("screenshot-save", index),
+ "screenshot-save",
"icons/download.svg",
"Save as",
false,
@@ -2644,7 +2643,7 @@ impl SettingsWindow {
},
))
.child(self.row_button(
- ("screenshot-folder", index),
+ "screenshot-folder",
"icons/folder.svg",
"Open folder",
false,
@@ -2652,7 +2651,7 @@ impl SettingsWindow {
move |_this, _window, cx| library::reveal_path(&bundle, cx),
))
.child(self.row_button(
- ("screenshot-delete", index),
+ "screenshot-delete",
"icons/trash.svg",
"Delete",
false,
@@ -2664,7 +2663,7 @@ impl SettingsWindow {
));
div()
- .id(("screenshot-row", index))
+ .id(gpui::ElementId::Path(item.path.as_path().into()))
.flex()
.flex_row()
.justify_between()