commands: fix MIME fallback in TUI; improve watch logging

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I67d0486ca9719b334957ff3868da3f0c6a6a6964
This commit is contained in:
raf 2026-05-03 17:19:32 +03:00
commit 9217b32798
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
2 changed files with 12 additions and 4 deletions

View file

@ -698,7 +698,7 @@ impl SqliteClipboardDb {
let mime_type = match mime {
Some(ref m) if m == "text/plain" => MimeType::Text,
Some(ref m) => MimeType::Specific(m.clone().clone()),
None => MimeType::Text,
None => MimeType::Autodetect,
};
let copy_result = opts
.copy(Source::Bytes(contents.clone().into()), mime_type);

View file

@ -435,6 +435,14 @@ impl WatchCommand for SqliteClipboardDb {
log::info!("clipboard entry excluded by app filter");
last_hash = Some(current_hash);
},
Err(crate::db::StashError::AllWhitespace) => {
log::debug!("clipboard entry is all whitespace, skipping");
last_hash = Some(current_hash);
},
Err(crate::db::StashError::TooSmall(_)) => {
log::debug!("clipboard entry below minimum size, skipping");
last_hash = Some(current_hash);
},
Err(e) => {
log::error!("failed to store clipboard entry: {e}");
last_hash = Some(current_hash);
@ -518,8 +526,8 @@ mod tests {
#[test]
fn test_pick_image_preference_falls_back() {
// No image types in offer set; first type is used as fallback.
let offered = vec!["text/html".to_string(), "text/plain".to_string()];
// No image types offered — falls back to first
assert_eq!(pick_mime(&offered, "image").unwrap(), "text/html");
}
@ -550,14 +558,14 @@ mod tests {
#[test]
fn test_pick_html_fallback_when_only_html() {
// When text/html is the only type, pick it
// text/html is used when it is the only offered type.
let offered = vec!["text/html".to_string()];
assert_eq!(pick_mime(&offered, "any").unwrap(), "text/html");
}
#[test]
fn test_pick_text_over_html_when_no_image() {
// Rich text copy: html + plain, no image — prefer plain text
// html + plain with no image type; plain text wins over html.
let offered = vec!["text/html".to_string(), "text/plain".to_string()];
assert_eq!(pick_mime(&offered, "any").unwrap(), "text/plain");
}