浏览代码

Add default keybindings for navigation

rigormorrtiss 4 年之前
父节点
当前提交
c17ca03bda
共有 2 个文件被更改,包括 22 次插入3 次删除
  1. 18 1
      discordo.go
  2. 4 2
      ui/app.go

+ 18 - 1
discordo.go

@@ -58,7 +58,7 @@ func main() {
 	channelsTreeView = ui.NewChannelsTreeView(channelsTreeNode, onChannelsTreeViewSelected, config.Theme)
 	messagesTextView = ui.NewMessagesTextView(onMessagesTextViewChanged, config.Theme)
 	mainFlex = ui.NewMainFlex(guildsDropDown, channelsTreeView, messagesTextView)
-	app = ui.NewApp()
+	app = ui.NewApp(onAppInputCapture)
 
 	token := util.GetPassword("token")
 	if token != "" {
@@ -76,6 +76,23 @@ func main() {
 	}
 }
 
+func onAppInputCapture(event *tcell.EventKey) *tcell.EventKey {
+	switch event.Name() {
+	case "Ctrl+G":
+		app.SetFocus(guildsDropDown)
+	case "Ctrl+J":
+		app.SetFocus(channelsTreeView)
+	case "Ctrl+K":
+		app.SetFocus(messagesTextView)
+	case "Ctrl+L":
+		if messageInputField != nil {
+			app.SetFocus(messageInputField)
+		}
+	}
+
+	return event
+}
+
 func onMessagesTextViewChanged() {
 	app.Draw()
 }

+ 4 - 2
ui/app.go

@@ -1,12 +1,14 @@
 package ui
 
 import (
+	"github.com/gdamore/tcell/v2"
 	"github.com/rivo/tview"
 )
 
-func NewApp() *tview.Application {
+func NewApp(onAppInputCapture func(event *tcell.EventKey) *tcell.EventKey) *tview.Application {
 	app := tview.NewApplication().
-		EnableMouse(true)
+		EnableMouse(true).
+		SetInputCapture(onAppInputCapture)
 
 	return app
 }