Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ image = { version = "0.25.9", features = ["tiff"] }
libc = "0.2.180"
log = "0.4.29"
minreq = { version = "2.14.1", features = ["https"] }
nucleo-matcher = "0.3.1"
objc2 = "0.6.3"
objc2-app-kit = { version = "0.3.2", features = ["NSImage", "NSScreen"] }
objc2-application-services = { version = "0.3.2", default-features = false, features = ["HIServices", "Processes"] }
Expand Down
30 changes: 22 additions & 8 deletions src/app/tile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ use iced::{
use iced::{event, window};

use log::{info, warn};
use nucleo_matcher::pattern::{CaseMatching, Normalization, Pattern};
use nucleo_matcher::{Matcher, Utf32Str};
use objc2::rc::Retained;
use objc2_app_kit::NSRunningApplication;
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
Expand All @@ -34,6 +36,7 @@ use tokio::io::{AsyncBufReadExt, AsyncRead};
use tray_icon::TrayIcon;
use url::Url;

use std::cell::RefCell;
use std::collections::HashMap;
use std::fmt::Debug;
use std::time::Duration;
Expand All @@ -56,15 +59,22 @@ struct AppIndex {
impl AppIndex {
/// Search for an element in the index that starts with the provided prefix
fn search_prefix<'a>(&'a self, prefix: &'a str) -> impl ParallelIterator<Item = &'a App> + 'a {
let pattern = Pattern::parse(prefix, CaseMatching::Ignore, Normalization::Smart);

self.by_name.par_iter().filter_map(move |(name, app)| {
if name.starts_with(prefix)
|| name.contains(format!(" {prefix}").as_str())
|| name.contains(format!("-{prefix}").as_str())
{
Some(app)
} else {
None
thread_local! {
static MATCHER: RefCell<Matcher> = RefCell::new(
Matcher::new(nucleo_matcher::Config::DEFAULT.match_paths())
);
}

MATCHER.with(|m| {
let mut buf = Vec::new();
let haystack = Utf32Str::new(name, &mut buf);
pattern
.score(haystack, &mut m.borrow_mut())
.map(|_score| app)
})
})
}

Expand Down Expand Up @@ -706,7 +716,11 @@ mod tests {
.map(|app| app.display_name.clone())
.collect();

assert_eq!(prefix_results, vec!["Safari".to_string()]);
assert!(
prefix_results.contains(&"Visual Studio Code".to_string())
&& prefix_results.contains(&"Signal Desktop".to_string())
&& prefix_results.contains(&"Safari".to_string()),
);
assert_eq!(spaced_results, vec!["Visual Studio Code".to_string()]);
assert_eq!(hyphen_results, vec!["Signal Desktop".to_string()]);
}
Expand Down
1 change: 0 additions & 1 deletion src/app/tile/elm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use crate::app::pages::settings::settings_page;
use crate::app::tile::{AppIndex, Hotkeys};
use crate::app::{DEFAULT_WINDOW_HEIGHT, HotkeyCapture, SettingsTab, ToApp, ToApps};
use crate::config::Theme;
use crate::database::load_clipboard;
use crate::debounce::Debouncer;
use crate::platform::macos::events::Event;
use crate::styles::{
Expand Down
12 changes: 0 additions & 12 deletions src/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,4 @@ mod tests {
ClipBoardContentType::Text("world".to_string())
);
}

#[test]
fn clipboard_to_app_truncates_and_uses_first_line_for_display() {
let item =
ClipBoardContentType::Text("abcdefghijklmnopqrstuvwxyz\nsecond line".to_string());

// let app = item.to_app();

// assert_eq!(app.display_name, "abcdefghijklmnopqrstuvwxy");
// assert_eq!(app.search_name, "abcdefghijklmnopqrstuvwxy");
// assert_eq!(app.desc, "Clipboard Item");
}
}
File renamed without changes.
Loading