You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import"fmt"func (f*Form) SetFocus(indexint) *Form {
ifindex<0 {
f.focusedElement=0
} elseifindex>=len(f.items)+len(f.buttons) {
f.focusedElement=len(f.items) +len(f.buttons)
} else {
f.focusedElement=index
}
iff.changed!=nil {
f.changed(f.focusedElement)
}
returnf
}
typeFormstruct {
items []stringbuttons []stringfocusedElementintchangedfunc(indexint)
}
funcmain() {
// Create a new Form instanceform:=&Form{
items: []string{"Item 1", "Item 2", "Item 3"},
buttons: []string{"Submit", "Cancel"},
changed: func(indexint) {
fmt.Printf("Focused element changed to index: %d\n", index)
},
}
// Set focus to different elementsform.SetFocus(0) // Focus on first itemform.SetFocus(3) // Focus on first buttonform.SetFocus(5) // Attempt to focus beyond the last elementform.SetFocus(-1) // Focus on the first element
}
After executing modernize -fix -test ./..., it will become.
package main
import"fmt"func (f*Form) SetFocus(indexint) *Form {
ifindex<0 {
f.focusedElement=0
} elsef.focusedElement=min(index, len(f.items) +len(f.buttons))
iff.changed!=nil {
f.changed(f.focusedElement)
}
returnf
}
typeFormstruct {
items []stringbuttons []stringfocusedElementintchangedfunc(indexint)
}
funcmain() {
// Create a new Form instanceform:=&Form{
items: []string{"Item 1", "Item 2", "Item 3"},
buttons: []string{"Submit", "Cancel"},
changed: func(indexint) {
fmt.Printf("Focused element changed to index: %d\n", index)
},
}
// Set focus to different elementsform.SetFocus(0) // Focus on first itemform.SetFocus(3) // Focus on first buttonform.SetFocus(5) // Attempt to focus beyond the last elementform.SetFocus(-1) // Focus on the first element
}
package main
import"fmt"func (f*Form) SetFocus(indexint) *Form {
ifindex<0 {
f.focusedElement=0
} else {
f.focusedElement=min(index, len(f.items)+len(f.buttons))
}
iff.changed!=nil {
f.changed(f.focusedElement)
}
returnf
}
typeFormstruct {
items []stringbuttons []stringfocusedElementintchangedfunc(indexint)
}
funcmain() {
// Create a new Form instanceform:=&Form{
items: []string{"Item 1", "Item 2", "Item 3"},
buttons: []string{"Submit", "Cancel"},
changed: func(indexint) {
fmt.Printf("Focused element changed to index: %d\n", index)
},
}
// Set focus to different elementsform.SetFocus(0) // Focus on first itemform.SetFocus(3) // Focus on first buttonform.SetFocus(5) // Attempt to focus beyond the last elementform.SetFocus(-1) // Focus on the first element
}
The text was updated successfully, but these errors were encountered:
gopherbot
added
Tools
This label describes issues relating to any tools in the x/tools repository.
gopls
Issues related to the Go language server, gopls.
labels
May 2, 2025
Go version
go 1.24.2
Output of
go env
in your module/workspace:What did you do?
The Output:
What did you see happen?
After executing
modernize -fix -test ./...,
it will become.Output:
What did you expect to see?
The text was updated successfully, but these errors were encountered: