From 01c838d8b00be24517423d92c46b7a8f73c1db4c Mon Sep 17 00:00:00 2001 From: ayntgl <90600421+ayntgl@users.noreply.github.com> Date: Tue, 6 Sep 2022 00:52:20 +0530 Subject: [PATCH] Set as new table if field not available in configuration file (#206) --- ui/core.go | 8 +++++--- ui/message_input.go | 4 ++-- ui/messages_panel.go | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/ui/core.go b/ui/core.go index a422715..ca30cb4 100644 --- a/ui/core.go +++ b/ui/core.go @@ -50,7 +50,7 @@ func NewCore(cfg *config.Config) *Core { Config: cfg, } - c.MainFlex.SetInputCapture(c.onInputCapture) + c.Application.SetInputCapture(c.onInputCapture) c.GuildsTree = NewGuildsTree(c) c.ChannelsTree = NewChannelsTree(c) c.MessagesPanel = NewMessagesPanel(c) @@ -136,12 +136,12 @@ func (c *Core) onInputCapture(e *tcell.EventKey) *tcell.EventKey { keysTable, ok := c.Config.State.GetGlobal("keys").(*lua.LTable) if !ok { - return e + keysTable = c.Config.State.NewTable() } applicationTable, ok := keysTable.RawGetString("application").(*lua.LTable) if !ok { - return e + applicationTable = c.Config.State.NewTable() } var fn lua.LValue @@ -276,6 +276,8 @@ func (c *Core) onStateGuildCreate(g *gateway.GuildCreateEvent) { rootNode := c.GuildsTree.GetRoot() rootNode.AddChild(guildNode) + c.GuildsTree.SetCurrentNode(rootNode) + c.Application.SetFocus(c.GuildsTree) c.Application.Draw() } diff --git a/ui/message_input.go b/ui/message_input.go index 7c54fda..a7e680f 100644 --- a/ui/message_input.go +++ b/ui/message_input.go @@ -42,12 +42,12 @@ func NewMessageInput(c *Core) *MessageInput { func (mi *MessageInput) onInputCapture(e *tcell.EventKey) *tcell.EventKey { keysTable, ok := mi.core.Config.State.GetGlobal("keys").(*lua.LTable) if !ok { - return e + keysTable = mi.core.Config.State.NewTable() } messageInputTable, ok := keysTable.RawGetString("messageInput").(*lua.LTable) if !ok { - return e + messageInputTable = mi.core.Config.State.NewTable() } var fn lua.LValue diff --git a/ui/messages_panel.go b/ui/messages_panel.go index 3e51a72..38e0f57 100644 --- a/ui/messages_panel.go +++ b/ui/messages_panel.go @@ -53,12 +53,12 @@ func (mp *MessagesPanel) onInputCapture(e *tcell.EventKey) *tcell.EventKey { keysTable, ok := mp.core.Config.State.GetGlobal("keys").(*lua.LTable) if !ok { - return e + keysTable = mp.core.Config.State.NewTable() } messagesPanel, ok := keysTable.RawGetString("messagesPanel").(*lua.LTable) if !ok { - return e + messagesPanel = mp.core.Config.State.NewTable() } var fn lua.LValue