Skip to content

Commit 3494622

Browse files
committed
plugins/applications: make entry_priority not optional
1 parent 2c528f1 commit 3494622

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

plugins/applications/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Config(
3333
)),
3434
3535
// Whether to prioritize actions or applications
36-
// Could be ActionsFirst, ApplicationsFirst, or NoPriority
37-
entry_priority: Some(ActionsFirst),
36+
// Could be ActionsFirst (default), ApplicationsFirst, or NoPriority
37+
entry_priority: ActionsFirst,
3838
)
3939
```

plugins/applications/src/lib.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ pub struct Config {
1111
max_entries: usize,
1212
terminal: Option<Terminal>,
1313
preprocess_exec_script: Option<PathBuf>,
14-
entry_priority: Option<EntryPriority>,
14+
15+
#[serde(default)]
16+
entry_priority: EntryPriority,
1517
}
1618

1719
#[derive(Deserialize)]
@@ -20,8 +22,9 @@ pub struct Terminal {
2022
args: String,
2123
}
2224

23-
#[derive(Deserialize)]
25+
#[derive(Deserialize, Default)]
2426
pub enum EntryPriority {
27+
#[default]
2528
ActionsFirst,
2629
ApplicationsFirst,
2730
NoPriority,
@@ -34,7 +37,7 @@ impl Default for Config {
3437
max_entries: 5,
3538
preprocess_exec_script: None,
3639
terminal: None,
37-
entry_priority: None,
40+
entry_priority: EntryPriority::default(),
3841
}
3942
}
4043
}
@@ -186,12 +189,6 @@ pub fn init(config_dir: RString) -> State {
186189
#[get_matches]
187190
pub fn get_matches(input: RString, state: &State) -> RVec<Match> {
188191
let matcher = fuzzy_matcher::skim::SkimMatcherV2::default().ignore_case();
189-
let entry_priority = state
190-
.config
191-
.entry_priority
192-
.as_ref()
193-
.unwrap_or(&EntryPriority::ActionsFirst);
194-
195192
let mut entries = state
196193
.entries
197194
.iter()
@@ -216,7 +213,7 @@ pub fn get_matches(input: RString, state: &State) -> RVec<Match> {
216213
let mut score = (name_score * 10 + desc_score + keyword_score) - entry.offset;
217214

218215
// Apply priority
219-
score *= match (entry_priority, entry.is_action) {
216+
score *= match (&state.config.entry_priority, entry.is_action) {
220217
(EntryPriority::ActionsFirst, true) => 2,
221218
(EntryPriority::ApplicationsFirst, false) => 2,
222219
_ => 1,

0 commit comments

Comments
 (0)