Skip to content

Commit 8816f3d

Browse files
committed
refactor: move CheckoutOptions change logic into next/previous methods
1 parent 4932690 commit 8816f3d

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

src/popups/checkout_option.rs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -131,25 +131,9 @@ impl CheckoutOptionPopup {
131131

132132
fn change_kind(&mut self, incr: bool) {
133133
self.option = if incr {
134-
match self.option {
135-
CheckoutOptions::KeepLocalChanges => {
136-
CheckoutOptions::Unchange
137-
}
138-
CheckoutOptions::Unchange => CheckoutOptions::Discard,
139-
CheckoutOptions::Discard => {
140-
CheckoutOptions::KeepLocalChanges
141-
}
142-
}
134+
self.option.next()
143135
} else {
144-
match self.option {
145-
CheckoutOptions::KeepLocalChanges => {
146-
CheckoutOptions::Discard
147-
}
148-
CheckoutOptions::Unchange => {
149-
CheckoutOptions::KeepLocalChanges
150-
}
151-
CheckoutOptions::Discard => CheckoutOptions::Unchange,
152-
}
136+
self.option.previous()
153137
};
154138
}
155139
}

src/strings.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,28 @@ pub enum CheckoutOptions {
446446
}
447447

448448
impl CheckoutOptions {
449+
pub fn previous(&self) -> Self {
450+
match self {
451+
CheckoutOptions::KeepLocalChanges => {
452+
CheckoutOptions::Discard
453+
}
454+
CheckoutOptions::Unchange => {
455+
CheckoutOptions::KeepLocalChanges
456+
}
457+
CheckoutOptions::Discard => CheckoutOptions::Unchange,
458+
}
459+
}
460+
461+
pub fn next(&self) -> Self {
462+
match self {
463+
CheckoutOptions::KeepLocalChanges => CheckoutOptions::Unchange,
464+
CheckoutOptions::Unchange => CheckoutOptions::Discard,
465+
CheckoutOptions::Discard => {
466+
CheckoutOptions::KeepLocalChanges
467+
}
468+
}
469+
}
470+
449471
pub fn to_string_pair(&self) -> (&'static str, &'static str) {
450472
const CHECKOUT_OPTION_STASH_AND_REAPPLY: &str =
451473
" 🟢 Stash and reapply changes";

0 commit comments

Comments
 (0)