Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions plugins/applications/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,9 @@ Config(
// {} is replaced with the command in the desktop entry
args: "-e {}",
)),

// Whether to prioritize actions or applications
// Could be ActionsFirst, ApplicationsFirst, or NoPriority
entry_priority: Some(ActionsFirst),
)
```
25 changes: 21 additions & 4 deletions plugins/applications/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct Config {
max_entries: usize,
terminal: Option<Terminal>,
preprocess_exec_script: Option<PathBuf>,
entry_priority: Option<EntryPriority>,
}

#[derive(Deserialize)]
Expand All @@ -19,13 +20,21 @@ pub struct Terminal {
args: String,
}

#[derive(Deserialize)]
pub enum EntryPriority {
ActionsFirst,
ApplicationsFirst,
NoPriority,
}

impl Default for Config {
fn default() -> Self {
Self {
desktop_actions: false,
max_entries: 5,
preprocess_exec_script: None,
terminal: None,
entry_priority: None,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the default behavior resolves to ActionsFirst, it should be reflected here. That should also be returned by a separate function Config::default_entry_priority or by a sufficient implementation of Default on EntryPriority.

}
}
}
Expand Down Expand Up @@ -177,6 +186,12 @@ pub fn init(config_dir: RString) -> State {
#[get_matches]
pub fn get_matches(input: RString, state: &State) -> RVec<Match> {
let matcher = fuzzy_matcher::skim::SkimMatcherV2::default().ignore_case();
let entry_priority = state
.config
.entry_priority
.as_ref()
.unwrap_or(&EntryPriority::ActionsFirst);

let mut entries = state
.entries
.iter()
Expand All @@ -200,10 +215,12 @@ pub fn get_matches(input: RString, state: &State) -> RVec<Match> {

let mut score = (name_score * 10 + desc_score + keyword_score) - entry.offset;

// prioritize actions
if entry.is_action {
score *= 2;
}
// Apply priority
score *= match (entry_priority, entry.is_action) {
(EntryPriority::ActionsFirst, true) => 2,
(EntryPriority::ApplicationsFirst, false) => 2,
_ => 1,
};

// Score cutoff
if score > 0 {
Expand Down