aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ui/textinput.go
diff options
context:
space:
mode:
authorMoritz Poldrack <git@moritz.sh>2022-07-31 14:32:48 +0200
committerRobin Jarry <robin@jarry.cc>2022-08-04 21:58:01 +0200
commit978d35d356e8752bdd272884df48a6289d88b40a (patch)
tree3910243e688ef503159d07ce44b22cfea5d6c6fd /lib/ui/textinput.go
parentc882cf9960be691fe55617b87cdfcfbabd5d5557 (diff)
downloadaerc-978d35d356e8752bdd272884df48a6289d88b40a.tar.gz
lint: homogenize operations and minor fixes (gocritic)
Apply GoDoc comment policy (comments for humans should have a space after the //; machine-readable comments shouldn't) Use strings.ReplaceAll instead of strings.Replace when appropriate Remove if/else chains by replacing them with switches Use short assignment/increment notation Replace single case switches with if statements Combine else and if when appropriate Signed-off-by: Moritz Poldrack <moritz@poldrack.dev> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib/ui/textinput.go')
-rw-r--r--lib/ui/textinput.go18
1 files changed, 7 insertions, 11 deletions
diff --git a/lib/ui/textinput.go b/lib/ui/textinput.go
index 8f8f00d0..70dcb3f5 100644
--- a/lib/ui/textinput.go
+++ b/lib/ui/textinput.go
@@ -148,10 +148,8 @@ func (ti *TextInput) drawPopover(ctx *Context) {
}
func (ti *TextInput) MouseEvent(localX int, localY int, event tcell.Event) {
- switch event := event.(type) {
- case *tcell.EventMouse:
- switch event.Buttons() {
- case tcell.Button1:
+ if event, ok := event.(*tcell.EventMouse); ok {
+ if event.Buttons() == tcell.Button1 {
if localX >= len(ti.prompt)+1 && localX <= len(ti.text[ti.scroll:])+len(ti.prompt)+1 {
ti.index = localX - len(ti.prompt) - 1
ti.ensureScroll()
@@ -190,7 +188,7 @@ func (ti *TextInput) ensureScroll() {
func (ti *TextInput) insert(ch rune) {
left := ti.text[:ti.index]
right := ti.text[ti.index:]
- ti.text = append(left, append([]rune{ch}, right...)...)
+ ti.text = append(left, append([]rune{ch}, right...)...) //nolint:gocritic // intentional append to different slice
ti.index++
ti.ensureScroll()
ti.Invalidate()
@@ -323,8 +321,7 @@ func (ti *TextInput) OnFocusLost(onFocusLost func(ti *TextInput)) {
}
func (ti *TextInput) Event(event tcell.Event) bool {
- switch event := event.(type) {
- case *tcell.EventKey:
+ if event, ok := event.(*tcell.EventKey); ok {
switch event.Key() {
case tcell.KeyBackspace, tcell.KeyBackspace2:
ti.invalidateCompletions()
@@ -464,8 +461,7 @@ func (c *completions) prev() {
}
func (c *completions) Event(e tcell.Event) bool {
- switch e := e.(type) {
- case *tcell.EventKey:
+ if e, ok := e.(*tcell.EventKey); ok {
switch e.Key() {
case tcell.KeyTab:
if len(c.options) == 1 && c.idx >= 0 {
@@ -496,7 +492,7 @@ func (c *completions) Event(e tcell.Event) bool {
}
func findStem(words []string) string {
- if len(words) <= 0 {
+ if len(words) == 0 {
return ""
}
if len(words) == 1 {
@@ -519,7 +515,7 @@ func findStem(words []string) string {
return stem
}
}
- stem = stem + string(r)
+ stem += string(r)
stemLen++
}
}