Commit 4b2382bf93

4b2382bf93e7a1f54f85610fd7a5acb2e33419cc

parent: 0f2442566f

Unregistered key

vaw <git@nlih.de> · 2025-10-25 20:00 UTC
committer: <noreply@github.com>

Fix image preview placeholder rendering (#483)

Layout: unified · split

src/message/mod.rs +14 −3
@@ -172,7 +172,8 @@ fn placeholder_frame(
172172 image_preview_size: &ImagePreviewSize,
173173) -> Option<String> {
174174 let ImagePreviewSize { width, height } = image_preview_size;
175 if outer_width < *width || (*width < 2 || *height < 2) {
175 let width = usize::min(*width, outer_width);
176 if width < 2 || *height < 2 {
176177 return None;
177178 }
178179 let mut placeholder = "\u{230c}".to_string();
@@ -1083,7 +1084,7 @@ impl Message {
10831084 },
10841085 ImageStatus::Loaded(backend) => {
10851086 proto = Some(backend);
1086 placeholder_frame(Some("Cut off..."), width, &backend.area().into())
1087 placeholder_frame(Some("No Space..."), width, &backend.area().into())
10871088 },
10881089 ImageStatus::Error(err) => Some(format!("[Image error: {err}]\n")),
10891090 };
@@ -1341,7 +1342,17 @@ pub mod tests {
13411342 )
13421343 );
13431344
1344 assert_eq!(placeholder_frame(None, 2, &ImagePreviewSize { width: 4, height: 4 }), None);
1345 assert_eq!(
1346 placeholder_frame(None, 2, &ImagePreviewSize { width: 4, height: 4 }),
1347 pretty_frame_test(
1348 r#"
1349⌌⌍
1350
1351
1352⌎⌏
1353"#
1354 )
1355 );
13451356 assert_eq!(placeholder_frame(None, 4, &ImagePreviewSize { width: 1, height: 4 }), None);
13461357
13471358 assert_eq!(placeholder_frame(None, 4, &ImagePreviewSize { width: 4, height: 1 }), None);