feat: add vi-like keybindings for guilds list (#161)

* Make guild list have vi like shortcuts

* Fix for g for guild

* use the short variable declaration operator

* Remove ifs

Co-authored-by: ayntgl <90600421+ayntgl@users.noreply.github.com>
This commit is contained in:
Matheus Fillipe 2022-08-12 05:42:42 -03:00 • committed by GitHub
parent 73e7eecd81
commit 05fb80f889
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,6 +5,7 @@ import (
"github.com/ayntgl/astatine"
"github.com/ayntgl/discordo/discord"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)
@ -26,9 +27,31 @@ func NewGuildsList(app *App) *GuildsList {
gl.SetBorder(true)
gl.SetBorderPadding(0, 0, 1, 1)
gl.SetSelectedFunc(gl.onSelected)
gl.SetInputCapture(gl.onInputCapture)
return gl
}
func (gl *GuildsList) onInputCapture(e *tcell.EventKey) *tcell.EventKey {
i := gl.List.GetCurrentItem()
switch e.Rune() {
case 'g': // Home.
i = 0
case 'G': // End.
i = gl.List.GetItemCount() - 1
case 'j': // Down.
i++
case 'k': // Up.
i--
if i < 0 {
i = 0
}
default:
return e
}
gl.List.SetCurrentItem(i)
return nil
}
func (gl *GuildsList) onSelected(idx int, mainText string, secondaryText string, shortcut rune) {
rootTreeNode := gl.app.ChannelsTreeView.GetRoot()
rootTreeNode.ClearChildren()