Skip to content

Commit

Permalink
feat: Updated search algorithm to match more items
Browse files Browse the repository at this point in the history
  • Loading branch information
PiotrekPKP committed May 21, 2022
1 parent a672ef3 commit bfb9f29
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 0 additions & 2 deletions src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,3 @@ pub const KEY_ESC: u32 = 9;
pub const KEY_LEFT_SHIFT: u32 = 50;
pub const KEY_RIGHT_SHIFT: u32 = 62;
pub const KEY_ENTER: u32 = 36;

pub const ITEMS_PER_PAGE: u32 = 9;
17 changes: 14 additions & 3 deletions src/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::crab_row::CrabRow;
use gtk::glib::{clone, MainContext, Object};
use gtk::prelude::*;
use gtk::subclass::prelude::*;
use gtk::{Adjustment, CustomFilter, FilterListModel, gio, Inhibit, ScrollType, SignalListItemFactory, SingleSelection};
use gtk::{CustomFilter, FilterListModel, gio, Inhibit, SignalListItemFactory, SingleSelection};
use gtk::{glib, Application, FilterChange};
use gtk::gio::{AppInfo};

Expand Down Expand Up @@ -41,7 +41,18 @@ impl Window {
let crab_entry = obj.downcast_ref::<gio::AppInfo>().unwrap();
let search = window.imp().entry.buffer().text();

if !search.is_empty() { crab_entry.name().to_lowercase().contains(&search.as_str().to_lowercase()) } else { true }
if !search.is_empty() {
crab_entry
.name()
.to_lowercase()
.contains(&search.as_str().to_lowercase()) || if crab_entry.description().is_some() {
crab_entry.description().unwrap().to_lowercase().contains(&search.as_str().to_lowercase())
} else {
false
}
} else {
true
}
}));

let filter_model = FilterListModel::new(Some(&self.current_items()), Some(&filter));
Expand Down Expand Up @@ -92,7 +103,7 @@ impl Window {
KEY_ESC => {
window.close();

Inhibit(false)
Inhibit(true)
}
KEY_ENTER => {
open_app(
Expand Down

0 comments on commit bfb9f29

Please sign in to comment.