feat: toggle guilds tree using keybinding (#297)
Co-authored-by: ayn2op <ayn2op@ayn2ops-MacBook-Air.local>
This commit is contained in:
parent
73fba28bd7
commit
a4152d4928
4 changed files with 29 additions and 5 deletions
|
|
@ -2,7 +2,8 @@ package config
|
|||
|
||||
type (
|
||||
GuildsTreeKeys struct {
|
||||
Focus string `yaml:"focus"`
|
||||
Focus string `yaml:"focus"`
|
||||
Toggle string `yaml:"toggle"`
|
||||
}
|
||||
|
||||
MessagesTextKeys struct {
|
||||
|
|
@ -44,7 +45,8 @@ func defKeys() Keys {
|
|||
Cancel: "Esc",
|
||||
|
||||
GuildsTree: GuildsTreeKeys{
|
||||
Focus: "Alt+Rune[g]",
|
||||
Focus: "Alt+Rune[g]",
|
||||
Toggle: "Alt+Rune[b]",
|
||||
},
|
||||
|
||||
MessagesText: MessagesTextKeys{
|
||||
|
|
|
|||
26
main_flex.go
26
main_flex.go
|
|
@ -23,6 +23,15 @@ func newMainFlex() *MainFlex {
|
|||
messageInput: newMessageInput(),
|
||||
}
|
||||
|
||||
mf.init()
|
||||
mf.SetInputCapture(mf.onInputCapture)
|
||||
|
||||
return mf
|
||||
}
|
||||
|
||||
func (mf *MainFlex) init() {
|
||||
mf.Clear()
|
||||
|
||||
right := tview.NewFlex()
|
||||
right.SetDirection(tview.FlexRow)
|
||||
right.AddItem(mf.messagesText, 0, 1, false)
|
||||
|
|
@ -30,13 +39,24 @@ func newMainFlex() *MainFlex {
|
|||
// The guilds tree is always focused first at start-up.
|
||||
mf.AddItem(mf.guildsTree, 0, 1, true)
|
||||
mf.AddItem(right, 0, 4, false)
|
||||
mf.SetInputCapture(mf.onInputCapture)
|
||||
|
||||
return mf
|
||||
}
|
||||
|
||||
func (mf *MainFlex) onInputCapture(event *tcell.EventKey) *tcell.EventKey {
|
||||
switch event.Name() {
|
||||
case config.Current.Keys.GuildsTree.Toggle:
|
||||
// The guilds tree is visible if the numbers of items is two.
|
||||
if mf.GetItemCount() == 2 {
|
||||
mf.RemoveItem(mf.guildsTree)
|
||||
|
||||
if mf.guildsTree.HasFocus() {
|
||||
app.SetFocus(mf)
|
||||
}
|
||||
} else {
|
||||
mf.init()
|
||||
app.SetFocus(mf.guildsTree)
|
||||
}
|
||||
|
||||
return nil
|
||||
case config.Current.Keys.GuildsTree.Focus:
|
||||
app.SetFocus(mf.guildsTree)
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ l l
|
|||
l l .
|
||||
\fB\fCAction\fR \fB\fCKeybinding\fR
|
||||
Focus Alt + g
|
||||
Toggle Alt + b
|
||||
.TE
|
||||
|
||||
.SS Messages Text
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ The default keybindings in the app are as follow
|
|||
| Action | Keybinding |
|
||||
| ------ | ---------- |
|
||||
| Focus | Alt + g |
|
||||
| Toggle | Alt + b |
|
||||
|
||||
### Messages Text
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue