From e44d6cd0bd56ffb62293344f67467909caced433 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Thu, 18 Jul 2024 18:11:37 -0400 Subject: [PATCH] fix(cosmic_toplevel): require higher score & match individual title words --- plugins/src/cosmic_toplevel/mod.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/plugins/src/cosmic_toplevel/mod.rs b/plugins/src/cosmic_toplevel/mod.rs index 56cc04f..78e7548 100644 --- a/plugins/src/cosmic_toplevel/mod.rs +++ b/plugins/src/cosmic_toplevel/mod.rs @@ -18,6 +18,7 @@ use pop_launcher::{ Request, }; use std::borrow::Cow; +use std::iter; use tokio::io::{AsyncWrite, AsyncWriteExt}; use self::toplevel_handler::{toplevel_handler, ToplevelAction, ToplevelEvent}; @@ -169,20 +170,23 @@ impl App { fde::matching::MatchAppIdOptions::default(), ) } else { + let lowercase_title = info.title.to_lowercase(); + let window_words = lowercase_title + .split_whitespace() + .chain(iter::once(info.app_id.as_str())) + .chain(iter::once(info.title.as_str())) + .collect::>(); + fde::matching::get_best_match( - &[&info.app_id, &info.title], + &window_words, &self.desktop_entries, fde::matching::MatchAppIdOptions::default(), ) .and_then(|de| { - let score = fde::matching::get_entry_score( - &query, - de, - &self.locales, - &[&info.app_id, &info.title], - ); + let score = + fde::matching::get_entry_score(&query, de, &self.locales, &window_words); - if score > 0.6 { + if score > 0.8 { Some(de) } else { None @@ -201,7 +205,6 @@ impl App { // XXX protocol id may be re-used later id: handle.id().protocol_id(), window: Some((0, handle.id().clone().protocol_id())), - // XXX: why this is inversed for this plugin ???? description: info.title.clone(), name: get_description(de, &self.locales), icon: Some(IconSource::Name(icon_name)),