Skip to content

Commit

Permalink
Use default pattern for theme mode reset
Browse files Browse the repository at this point in the history
  • Loading branch information
jmacdonald committed Sep 10, 2024
1 parent 9f699d0 commit 9201aca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/models/application/modes/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use fragment;
use std::fmt;
use std::slice::Iter;

#[derive(Default)]
pub struct ThemeMode {
insert: bool,
input: String,
Expand All @@ -15,17 +16,19 @@ pub struct ThemeMode {
impl ThemeMode {
pub fn new(config: SearchSelectConfig) -> ThemeMode {
ThemeMode {
insert: true,
input: String::new(),
themes: Vec::new(),
results: SelectableVec::new(Vec::new()),
config,
insert: true,
..Default::default()
}
}

pub fn reset(&mut self, themes: Vec<String>, config: SearchSelectConfig) {
self.themes = themes;
self.config = config;
*self = ThemeMode {
config,
insert: true,
themes,
..Default::default()
};
}
}

Expand Down
1 change: 1 addition & 0 deletions src/util/selectable_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::ops::Deref;
/// A simple decorator around a Vec that allows a single element to be selected.
/// The selection can be incremented/decremented in single steps, and the
/// selected value wraps when moved beyond either edge of the set.
#[derive(Default)]
pub struct SelectableVec<T> {
set: Vec<T>,
selected_index: usize,
Expand Down

0 comments on commit 9201aca

Please sign in to comment.