Skip to content

Commit

Permalink
feat: Add fuzzy matching to vrsjmp via nucleo-matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
leoshimo committed Feb 16, 2024
1 parent 49e3f20 commit 26c1188
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
1 change: 1 addition & 0 deletions vrsjmp/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
window-vibrancy = "0.4"
tracing = "0.1.40"
nucleo-matcher = "0.3.0"

[features]
# this feature is used for production builds or when `devPath` points to the filesystem
Expand Down
54 changes: 51 additions & 3 deletions vrsjmp/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,64 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

use std::sync::Mutex;

use nucleo_matcher::{
pattern::{CaseMatching, Normalization, Pattern},
Matcher,
};
use serde_json::json;
use tauri::{GlobalShortcutManager, Manager};

#[cfg(target_os = "macos")]
use window_vibrancy::{apply_vibrancy, NSVisualEffectMaterial, NSVisualEffectState};

struct State {
matcher: Mutex<Matcher>,
}

impl State {
fn new() -> Self {
Self {
matcher: Mutex::new(Matcher::default()),
}
}
}

#[tauri::command]
fn set_query(query: &str) -> Vec<serde_json::Value> {
fn set_query(query: &str, state: tauri::State<State>) -> Vec<serde_json::Value> {
let mut matcher = state.matcher.lock().unwrap();

// TODO: Integrate with Client
let items = vec![
"Open File",
"New Document",
"Save",
"Save As...",
"Close Window",
"Undo",
"Redo",
"Cut",
"Copy",
"Paste",
"Find",
"Replace",
"Go To Line",
"Select All",
"Preferences",
"Toggle Fullscreen",
"Zoom In",
"Zoom Out",
"Help",
"Exit",
];

let matches = Pattern::parse(query, CaseMatching::Smart, Normalization::Smart)
.match_list(items, &mut matcher);

let mut result = vec![];
for i in 0..=10 {
for (i, _) in matches {
result.push(json!({
"title": format!("{} {}", query, i),
"title": format!("{}", i),
"on_click": format!("(send {})", i),
}))
}
Expand All @@ -25,6 +72,7 @@ fn dispatch(form: &str) {

fn main() {
tauri::Builder::default()
.manage(State::new())
.setup(|app| {
let window = app.get_window("main").unwrap();

Expand Down

0 comments on commit 26c1188

Please sign in to comment.