Skip to content

Commit 0e19547

Browse files
committed
chore: simplify if statements
1 parent 6e055df commit 0e19547

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

Diff for: components/Sidebar.go

+21-16
Original file line numberDiff line numberDiff line change
@@ -79,32 +79,37 @@ func (sidebar *Sidebar) AddField(title, text string, fieldWidth int) {
7979
func (sidebar *Sidebar) FocusNextField() {
8080
newIndex := sidebar.GetCurrentFieldIndex() + 1
8181

82-
if newIndex < sidebar.Flex.GetItemCount() {
83-
item := sidebar.Fields[newIndex]
82+
if newIndex >= sidebar.Flex.GetItemCount() {
83+
return
84+
}
8485

85-
if item != nil {
86-
sidebar.SetCurrentFieldIndex(newIndex)
87-
App.SetFocus(item)
88-
App.ForceDraw()
89-
return
90-
}
86+
item := sidebar.Fields[newIndex]
9187

88+
if item == nil {
89+
return
9290
}
91+
92+
sidebar.SetCurrentFieldIndex(newIndex)
93+
App.SetFocus(item)
94+
App.ForceDraw()
9395
}
9496

9597
func (sidebar *Sidebar) FocusPreviousField() {
9698
newIndex := sidebar.GetCurrentFieldIndex() - 1
9799

98-
if newIndex >= 0 {
99-
item := sidebar.Fields[newIndex]
100+
if newIndex < 0 {
101+
return
102+
}
100103

101-
if item != nil {
102-
sidebar.SetCurrentFieldIndex(newIndex)
103-
App.SetFocus(item)
104-
App.ForceDraw()
105-
return
106-
}
104+
item := sidebar.Fields[newIndex]
105+
106+
if item == nil {
107+
return
107108
}
109+
110+
sidebar.SetCurrentFieldIndex(newIndex)
111+
App.SetFocus(item)
112+
App.ForceDraw()
108113
}
109114

110115
func (sidebar *Sidebar) FocusFirstField() {

0 commit comments

Comments
 (0)